Skip to content

Commit

Permalink
fix: allow opt-in refresh_token grant without offline_access as in 5.x
Browse files Browse the repository at this point in the history
closes #647
  • Loading branch information
panva committed Feb 14, 2020
1 parent 3f89012 commit b67a3a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Configuration {
}
});

if (this.scopes.has('offline_access')) {
if (this.scopes.has('offline_access') || this.issueRefreshToken !== defaults.issueRefreshToken) {
this.grantTypes.add('refresh_token');
}

Expand Down
30 changes: 30 additions & 0 deletions test/configuration/offline_access.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { expect } = require('chai');

const { Provider } = require('../../lib');

describe('Provider declaring support for refresh_token grant type', () => {
it('is enabled by default', () => {
const provider = new Provider('https://op.example.com');
expect(i(provider).configuration().grantTypes).to.contain('refresh_token');
});

it('isnt enabled when offline_access isnt amongst the scopes', () => {
const provider = new Provider('https://op.example.com', { scopes: ['openid'] });
expect(i(provider).configuration().grantTypes).not.to.contain('refresh_token');
});

it('is enabled when offline_access isnt amongst the scopes', () => {
const provider = new Provider('https://op.example.com', { scopes: ['openid', 'offline_access'] });
expect(i(provider).configuration().grantTypes).to.contain('refresh_token');
});

it('is enabled when issueRefreshToken configuration function is configured', () => {
const provider = new Provider('https://op.example.com', {
scopes: ['openid'],
issueRefreshToken() {
return true;
},
});
expect(i(provider).configuration().grantTypes).to.contain('refresh_token');
});
});

0 comments on commit b67a3a6

Please sign in to comment.