Skip to content

Commit c597a24

Browse files
committed
only add code challenge properties to code when codeChallenge and codeChallengeMethod ar set
1 parent c599cb4 commit c597a24

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lib/handlers/authorize-handler.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,19 @@ AuthorizeHandler.prototype.getRedirectUri = function(request, client) {
296296
*/
297297

298298
AuthorizeHandler.prototype.saveAuthorizationCode = function(authorizationCode, expiresAt, scope, client, redirectUri, user, codeChallenge, codeChallengeMethod) {
299-
const code = {
299+
let code = {
300300
authorizationCode: authorizationCode,
301301
expiresAt: expiresAt,
302302
redirectUri: redirectUri,
303-
scope: scope,
304-
codeChallenge: codeChallenge,
305-
codeChallengeMethod: codeChallengeMethod
303+
scope: scope
306304
};
305+
306+
if(codeChallenge && codeChallengeMethod){
307+
code = Object.assign({
308+
codeChallenge: codeChallenge,
309+
codeChallengeMethod: codeChallengeMethod
310+
}, code);
311+
}
307312
return promisify(this.model.saveAuthorizationCode, 3).call(this.model, code, client, user);
308313
};
309314

test/unit/handlers/authorize-handler_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ describe('AuthorizeHandler', function() {
8787
};
8888
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
8989

90+
return handler.saveAuthorizationCode('foo', 'bar', 'qux', 'biz', 'baz', 'boz')
91+
.then(function() {
92+
model.saveAuthorizationCode.callCount.should.equal(1);
93+
model.saveAuthorizationCode.firstCall.args.should.have.length(3);
94+
model.saveAuthorizationCode.firstCall.args[0].should.eql({ authorizationCode: 'foo', expiresAt: 'bar', redirectUri: 'baz', scope: 'qux' });
95+
model.saveAuthorizationCode.firstCall.args[1].should.equal('biz');
96+
model.saveAuthorizationCode.firstCall.args[2].should.equal('boz');
97+
model.saveAuthorizationCode.firstCall.thisValue.should.equal(model);
98+
})
99+
.catch(should.fail);
100+
});
101+
102+
it('should call `model.saveAuthorizationCode()` with code challenge', function() {
103+
const model = {
104+
getAccessToken: function() {},
105+
getClient: function() {},
106+
saveAuthorizationCode: sinon.stub().returns({})
107+
};
108+
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
109+
90110
return handler.saveAuthorizationCode('foo', 'bar', 'qux', 'biz', 'baz', 'boz', 'codeChallenge', 'codeChallengeMethod')
91111
.then(function() {
92112
model.saveAuthorizationCode.callCount.should.equal(1);

0 commit comments

Comments
 (0)