oauth2orize icon indicating copy to clipboard operation
oauth2orize copied to clipboard

oauth2orize error: unsupported response type: code

Open about2r2i opened this issue 9 years ago • 3 comments

Attempting to use oauth2orize to setup an authorization server for authorization code grant flow with a passport local strategy. Having issues after authenticating user when attempting to validate the client.

oauth.js 

 export const authorization = [  
   function(req, res, next) {  
     if (req.user) next(); //valid authentication
     else res.redirect('/oauth/authorization');
  },
  server.authorization(function(clientId, redirectURI, done) {
   Client.findOne(clientId, function(err, client) {
      if (err) { return done(err); }
      if (!client) { return done(null, false); }
      if (!(client.redirecturi != redirectURI)) { return done(null, false); }
      return done(null, client, <string>client.redirecturi);
   });
 
 })...]

Getting the following error from the middleware method server.authorization https://github.com/jaredhanson/oauth2orize/blob/master/lib/middleware/authorization.js, line: 121

AuthorizationError: Unsupported response type: code

The particular line of code inside the middleware which is throwing the error is

    if (areq.type && !areq.clientID) { 
       return next(new AuthorizationError('Unsupported response type: ' + type,    'unsupported_response_type')); 
   }

Where areq.clientID is NULL and hence triggering the error handler. areq is a JSON object which is being built using server._parse on the request. Right now it only has the {type: code} property in it.

The authentication workflow responsible for authenticating the user is:

    app.post('/oauth/authorization', passportlocal.authenticate('local', {   failureRedirect: '/oauth/authorization' }), function(req, res) {    

    res.redirect('/authorization?response_type=' + req.body.responseType + '&client_id=' + req.body.clientId + '&redirect_uri=' + req.body.redirectUri)
      })


    app.get('/authorization', oauth.authorization) 

What am I missing in the workflow that is not initializing the clientID?

about2r2i avatar Mar 28 '17 14:03 about2r2i

Did you ever manage to solve this? Facing the same issue. Documentation is lacking.

felixfrtz avatar Nov 17 '17 13:11 felixfrtz

@warhost can you provide a sample that reproduces the issue?

sandrinodimattia avatar Nov 18 '17 00:11 sandrinodimattia

Nevermind, it works now with the example consumer.

felixfrtz avatar Nov 21 '17 10:11 felixfrtz