jaredhanson / jaredhanson/oauth2orize

oauth2orize error: unsupported response type: code

Open
#200 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.5k
Forks
472
PR merge metrics
No merged PRs in 30d

Description

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, 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?

Contributor guide

Open the contributing guide

Research direction

Start by tracing the request through app.get('/authorization', oauth.authorization) and server._parse, then inspect lib/middleware/authorization.js around line 121. Compare the parsed request with the redirect assembled in the authentication route and verify the authorization-code flow supplies the expected client fields. Done means the request reaches the middleware with a client ID and no longer raises the unsupported response type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js
Domain
api, authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.