oauth2orize error: unsupported response type: code
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?
Did you ever manage to solve this? Facing the same issue. Documentation is lacking.
@warhost can you provide a sample that reproduces the issue?
Nevermind, it works now with the example consumer.