Skip to content

Only require 'redirect_uri' in token/authorization_code when one was provided in authorize/code #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/handlers/authorize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ AuthorizeHandler.prototype.handle = function(request, response) {
return Promise.all(fns)
.bind(this)
.spread(function(expiresAt, client, user) {
var uri = this.getRedirectUri(request, client);
var { uri, requestUri } = this.getRedirectUri(request, client);
var scope;
var state;
var ResponseType;
Expand All @@ -111,7 +111,7 @@ AuthorizeHandler.prototype.handle = function(request, response) {
state = this.getState(request);
ResponseType = this.getResponseType(request);

return this.saveAuthorizationCode(authorizationCode, expiresAt, scope, client, uri, user);
return this.saveAuthorizationCode(authorizationCode, expiresAt, scope, client, requestUri, user);
})
.then(function(code) {
var responseType = new ResponseType(code.authorizationCode);
Expand Down Expand Up @@ -273,7 +273,10 @@ AuthorizeHandler.prototype.getUser = function(request, response) {
*/

AuthorizeHandler.prototype.getRedirectUri = function(request, client) {
return request.body.redirect_uri || request.query.redirect_uri || client.redirectUris[0];
var requestUri = request.body.redirect_uri || request.query.redirect_uri;
var uri = requestUri || client.redirectUris[0];

return { uri, requestUri };
};

/**
Expand Down
39 changes: 39 additions & 0 deletions test/integration/handlers/authorize-handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,45 @@ describe('AuthorizeHandler integration', function() {
});
});

it('should not include redirectUri in model.saveAuthorizationCode() when its not in request', function() {
var model = {
getAccessToken: function() {
return {
user: {},
accessTokenExpiresAt: new Date(new Date().getTime() + 10000)
};
},
getClient: function() {
return { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };
},
saveAuthorizationCode: function(code) {
code.should.have.property('redirectUri').which.is.undefined();
return { authorizationCode: 12345, client: this.getClient() };
}
};
var handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
var request = new Request({
body: {
client_id: 12345,
response_type: 'code'
},
headers: {
'Authorization': 'Bearer foo'
},
method: {},
query: {
state: 'foobar'
}
});
var response = new Response({ body: {}, headers: {} });

return handler.handle(request, response)
.then(should.fail)
.catch(function() {
response.get('location').should.equal('http://example.com/cb?code=12345&state=foobar');
});
});

it('should return the `code` if successful', function() {
var client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };
var model = {
Expand Down