Skip to content

Commit

Permalink
only add code challenge properties to code when codeChallenge and cod…
Browse files Browse the repository at this point in the history
…eChallengeMethod ar set
  • Loading branch information
martinssonj committed Oct 31, 2022
1 parent c599cb4 commit c597a24
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/handlers/authorize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,19 @@ AuthorizeHandler.prototype.getRedirectUri = function(request, client) {
*/

AuthorizeHandler.prototype.saveAuthorizationCode = function(authorizationCode, expiresAt, scope, client, redirectUri, user, codeChallenge, codeChallengeMethod) {
const code = {
let code = {
authorizationCode: authorizationCode,
expiresAt: expiresAt,
redirectUri: redirectUri,
scope: scope,
codeChallenge: codeChallenge,
codeChallengeMethod: codeChallengeMethod
scope: scope
};

if(codeChallenge && codeChallengeMethod){
code = Object.assign({
codeChallenge: codeChallenge,
codeChallengeMethod: codeChallengeMethod
}, code);
}
return promisify(this.model.saveAuthorizationCode, 3).call(this.model, code, client, user);
};

Expand Down
20 changes: 20 additions & 0 deletions test/unit/handlers/authorize-handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ describe('AuthorizeHandler', function() {
};
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });

return handler.saveAuthorizationCode('foo', 'bar', 'qux', 'biz', 'baz', 'boz')
.then(function() {
model.saveAuthorizationCode.callCount.should.equal(1);
model.saveAuthorizationCode.firstCall.args.should.have.length(3);
model.saveAuthorizationCode.firstCall.args[0].should.eql({ authorizationCode: 'foo', expiresAt: 'bar', redirectUri: 'baz', scope: 'qux' });
model.saveAuthorizationCode.firstCall.args[1].should.equal('biz');
model.saveAuthorizationCode.firstCall.args[2].should.equal('boz');
model.saveAuthorizationCode.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});

it('should call `model.saveAuthorizationCode()` with code challenge', function() {
const model = {
getAccessToken: function() {},
getClient: function() {},
saveAuthorizationCode: sinon.stub().returns({})
};
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });

return handler.saveAuthorizationCode('foo', 'bar', 'qux', 'biz', 'baz', 'boz', 'codeChallenge', 'codeChallengeMethod')
.then(function() {
model.saveAuthorizationCode.callCount.should.equal(1);
Expand Down

0 comments on commit c597a24

Please sign in to comment.