Skip to content
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

Set the default token validation leeway to 60 sec #1062

Merged
merged 2 commits into from
Dec 17, 2019
Merged
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
2 changes: 1 addition & 1 deletion src/web-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ WebAuth.prototype.validateToken = function(token, nonce, cb) {
issuer: this.baseOptions.token_issuer,
jwksURI: this.baseOptions.jwksURI,
audience: this.baseOptions.clientID,
leeway: this.baseOptions.leeway || 0,
leeway: this.baseOptions.leeway || 60,
maxAge: this.baseOptions.maxAge,
__clock: this.baseOptions.__clock || defaultClock
});
Expand Down
42 changes: 42 additions & 0 deletions test/web-auth/web-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,47 @@ describe('auth0.WebAuth', function() {
});

context('validateToken', function() {
it('should send through a default leeway', function(done) {
var idTokenVerifierMock = function(opts) {
expect(opts.leeway).to.be(60);
done();
};

var { default: ProxiedWebAuth } = proxyquire('../../src/web-auth', {
'idtoken-verifier': idTokenVerifierMock
});

var webAuth = new ProxiedWebAuth({
domain: 'brucke.auth0.com',
redirectUri: 'http://example.com/callback',
clientID: 'k5u3o2fiAA8XweXEEX604KCwCjzjtMU6',
responseType: 'token id_token'
});

webAuth.validateToken('token', 'nonce', function() {});
});

it('should accept a specified leeway', function(done) {
var idTokenVerifierMock = function(opts) {
expect(opts.leeway).to.be(25);
done();
};

var { default: ProxiedWebAuth } = proxyquire('../../src/web-auth', {
'idtoken-verifier': idTokenVerifierMock
});

var webAuth = new ProxiedWebAuth({
domain: 'brucke.auth0.com',
redirectUri: 'http://example.com/callback',
clientID: 'k5u3o2fiAA8XweXEEX604KCwCjzjtMU6',
responseType: 'token id_token',
leeway: 25
});

webAuth.validateToken('token', 'nonce', function() {});
});

it('should use undefined jwksURI, allowing it to be overwritten later', function(done) {
var idTokenVerifierMock = function(opts) {
expect(opts.jwksURI).to.be(undefined);
Expand All @@ -2880,6 +2921,7 @@ describe('auth0.WebAuth', function() {

webAuth.validateToken('token', 'nonce', function() {});
});

it('should use correct jwksURI when overriden', function(done) {
var idTokenVerifierMock = function(opts) {
expect(opts.jwksURI).to.be('jwks_uri');
Expand Down