Skip to content

Commit

Permalink
Add refreshToken to authorization code grant type
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofgs committed Jan 5, 2016
1 parent 642bb70 commit 52e708b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/grant-types/authorization-code-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,18 @@ AuthorizationCodeGrantType.prototype.revokeAuthorizationCode = function(code) {
*/

AuthorizationCodeGrantType.prototype.saveToken = function(user, client, authorizationCode, scope) {
return this.generateAccessToken()
const fns = [
this.generateAccessToken(),
this.generateRefreshToken()
];

return Promise.all(fns)
.bind(this)
.then(function(accessToken) {
.spread(function(accessToken, refreshToken) {
var token = {
accessToken: accessToken,
authorizationCode: authorizationCode,
refreshToken: refreshToken,
scope: scope
};

Expand Down
3 changes: 2 additions & 1 deletion test/unit/grant-types/authorization-code-grant-type_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ describe('AuthorizationCodeGrantType', function() {
var handler = new AuthorizationCodeGrantType({ accessTokenLifetime: 120, model: model });

sinon.stub(handler, 'generateAccessToken').returns(Promise.resolve('foo'));
sinon.stub(handler, 'generateRefreshToken').returns(Promise.resolve('bar'));

return handler.saveToken(user, client, 'foobar', 'foobiz')
.then(function() {
model.saveToken.callCount.should.equal(1);
model.saveToken.firstCall.args.should.have.length(3);
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', authorizationCode: 'foobar', scope: 'foobiz' });
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', authorizationCode: 'foobar', refreshToken: 'bar', scope: 'foobiz' });
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
})
Expand Down

0 comments on commit 52e708b

Please sign in to comment.