Skip to content

Commit

Permalink
Set the default token validation leeway to 60 sec (#1062)
Browse files Browse the repository at this point in the history
* Set the default token validation leeway to 60 sec

* Added tests for leeway configuration
  • Loading branch information
Steve Hobbs authored Dec 17, 2019
1 parent 101d692 commit e58310e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
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

0 comments on commit e58310e

Please sign in to comment.