-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validating tokens according to response_type and access_tokens
- Loading branch information
Showing
7 changed files
with
109 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ var expect = require('expect.js'); | |
var stub = require('sinon').stub; | ||
var spy = require('sinon').spy; | ||
var request = require('superagent'); | ||
var IdTokenVerifier = require('idtoken-verifier'); | ||
|
||
var storage = require('../../src/helper/storage'); | ||
var windowHelper = require('../../src/helper/window'); | ||
|
@@ -271,9 +272,18 @@ describe('auth0.WebAuth', function() { | |
|
||
beforeEach(function() { | ||
spy(ssodata, 'set'); | ||
stub(IdTokenVerifier.prototype, 'validateAccessToken', function(at, alg, atHash, cb) { | ||
cb(null); | ||
}); | ||
}); | ||
afterEach(function() { | ||
ssodata.set.restore(); | ||
if (IdTokenVerifier.prototype.validateAccessToken.restore) { | ||
IdTokenVerifier.prototype.validateAccessToken.restore(); | ||
} | ||
if (WebAuth.prototype.validateToken.restore) { | ||
WebAuth.prototype.validateToken.restore(); | ||
} | ||
}); | ||
|
||
it('should parse a valid hash without id_token', function(done) { | ||
|
@@ -307,6 +317,75 @@ describe('auth0.WebAuth', function() { | |
} | ||
); // eslint-disable-line | ||
}); | ||
it('should return the id_token payload when there is no access_token', function(done) { | ||
var webAuth = new WebAuth({ | ||
domain: 'brucke.auth0.com', | ||
redirectUri: 'http://example.com/callback', | ||
clientID: 'k5u3o2fiAA8XweXEEX604KCwCjzjtMU6', | ||
responseType: 'id_token', | ||
__disableExpirationCheck: true | ||
}); | ||
|
||
var data = webAuth.parseHash( | ||
{ | ||
hash: '#state=foo&token_type=Bearer&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5FVkJOVU5CT1RneFJrRTVOa1F6UXpjNE9UQkVNRUZGUkRRNU4wUTJRamswUmtRMU1qRkdNUSJ9.eyJuaWNrbmFtZSI6ImpvaG5mb28iLCJuYW1lIjoiam9obmZvb0BnbWFpbC5jb20iLCJwaWN0dXJlIjoiaHR0cHM6Ly9zLmdyYXZhdGFyLmNvbS9hdmF0YXIvMzhmYTAwMjQyM2JkOGM5NDFjNmVkMDU4OGI2MGZmZWQ_cz00ODAmcj1wZyZkPWh0dHBzJTNBJTJGJTJGY2RuLmF1dGgwLmNvbSUyRmF2YXRhcnMlMkZqby5wbmciLCJ1cGRhdGVkX2F0IjoiMjAxOC0wMy0xNFQxNjozNDo1Ni40MjNaIiwiZW1haWwiOiJqb2huZm9vQGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiaXNzIjoiaHR0cHM6Ly9icnVja2UuYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDVhMjA1NGZmNDUxNTc3MTFiZTgxODJmNCIsImF1ZCI6Ims1dTNvMmZpQUE4WHdlWEVFWDYwNEtDd0Nqemp0TVU2IiwiaWF0IjoxNTIxMDQ1Mjk2LCJleHAiOjE1MjEwODEyOTYsImF0X2hhc2giOiJjZHVrb2FVc3dNOW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uY29tLyIsInN1YiI6ImF1dGgwfDVhMjA1NGZmNDUxNTc3MTFiZTgxODJmNCIsImF1ZCI6Ims1dTNvMmZpQUE4WHdlWEVFWDYwNEtDd0Nqemp0TVU2IiwiaWF0IjoxNTIxMDQ1Mjk2LCJleHAiOjE1MjEwODEyOTYsImF0X2hhc2giOiJjZHVrb2FVc3dNOWJvX3l6cmdWY3J3Iiwibm9uY2UiOiJsRkNuSTguY3JSVGRIZmRvNWsuek1YZlIzMTg1NmdLeiJ9.U4_F5Zw6xYVoHGiiem1wjz7i9eRaSOrt-L1e6hlu3wmqA-oNuVqf1tEYD9u0z5AbXXbQSr491A3VvUbLKjws13XETcljhaqigZ9q4HBpmzPlrUGmPreBLVQgGOaq5NVAViFTvORxYCMFLlc-SE6QI6xWF0AhFpoW7-hkOcOzXWAXqhkMgwAfjJ9aeOzSBgblmtx4duyNESBRefd3XPQrakWjGIqH3dFdc-lDFbY76eSLYfBi4AH-yim4egzB6LYOC-e2huZcHdmRAmEQaKZ7D7COBiGsgAPVGyjZtqfSQ2CRwNrAbxDwi8BqlLhQePOs6d3hqV-3OPLfdE6dUFh2DQ', | ||
idTokenPayload: { | ||
nickname: 'johnfoo', | ||
name: '[email protected]', | ||
picture: 'https://s.gravatar.com/avatar/38fa002423bd8c941c6ed0588b60ffed?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fjo.png', | ||
updated_at: '2018-03-14T16:34:56.423Z', | ||
email: '[email protected]', | ||
email_verified: false, | ||
iss: 'https://brucke.auth0.com/', | ||
sub: 'auth0|5a2054ff45157711be8182f4', | ||
aud: 'k5u3o2fiAA8XweXEEX604KCwCjzjtMU6', | ||
iat: 1521045296, | ||
exp: 1521081296, | ||
at_hash: 'cdukoaUswM9bo_yzrgVcrw', | ||
nonce: 'lFCnI8.crRTdHfdo5k.zMXfR31856gKz' | ||
}, | ||
appState: null, | ||
refreshToken: null, | ||
state: 'foo', | ||
expiresIn: null, | ||
tokenType: 'Bearer', | ||
scope: null | ||
}); | ||
done(); | ||
} | ||
); // eslint-disable-line | ||
}); | ||
it('should validate an access_token when available', function(done) { | ||
var webAuth = new WebAuth({ | ||
domain: 'brucke.auth0.com', | ||
redirectUri: 'http://example.com/callback', | ||
clientID: 'k5u3o2fiAA8XweXEEX604KCwCjzjtMU6', | ||
responseType: 'token id_token', | ||
__disableExpirationCheck: true | ||
}); | ||
IdTokenVerifier.prototype.validateAccessToken.restore(); | ||
|
||
var data = webAuth.parseHash( | ||
{ | ||
hash: '#state=foo&token_type=Bearer&access_token=YTvJcYrrZYHUXLZK5leLnfmD5ZIA_EA&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5FVkJOVU5CT1RneFJrRTVOa1F6UXpjNE9UQkVNRUZGUkRRNU4wUTJRamswUmtRMU1qRkdNUSJ9.eyJuaWNrbmFtZSI6ImpvaG5mb28iLCJuYW1lIjoiam9obmZvb0BnbWFpbC5jb20iLCJwaWN0dXJlIjoiaHR0cHM6Ly9zLmdyYXZhdGFyLmNvbS9hdmF0YXIvMzhmYTAwMjQyM2JkOGM5NDFjNmVkMDU4OGI2MGZmZWQ_cz00ODAmcj1wZyZkPWh0dHBzJTNBJTJGJTJGY2RuLmF1dGgwLmNvbSUyRmF2YXRhcnMlMkZqby5wbmciLCJ1cGRhdGVkX2F0IjoiMjAxOC0wMy0xNFQxNjozNDo1Ni40MjNaIiwiZW1haWwiOiJqb2huZm9vQGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiaXNzIjoiaHR0cHM6Ly9icnVja2UuYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDVhMjA1NGZmNDUxNTc3MTFiZTgxODJmNCIsImF1ZCI6Ims1dTNvMmZpQUE4WHdlWEVFWDYwNEtDd0Nqemp0TVU2IiwiaWF0IjoxNTIxMDQ1Mjk2LCJleHAiOjE1MjEwODEyOTYsImF0X2hhc2giOiJjZHVrb2FVc3dNOWJvX3l6cmdWY3J3Iiwibm9uY2UiOiJsRkNuSTguY3JSVGRIZmRvNWsuek1YZlIzMTg1NmdLeiJ9.U4_F5Zw6xYVoHGiiem1wjz7i9eRaSOrt-L1e6hlu3wmqA-oNuVqf1tEYD9u0z5AbXXbQSr491A3VvUbLKjws13XETcljhaqigZ9q4HBpmzPlrUGmPreBLVQgGOaq5NVAViFTvORxYCMFLlc-SE6QI6xWF0AhFpoW7-hkOcOzXWAXqhkMgwAfjJ9aeOzSBgblmtx4duyNESBRefd3XPQrakWjGIqH3dFdc-lDFbY76eSLYfBi4AH-yim4egzB6LYOC-e2huZcHdmRAmEQaKZ7D7COBiGsgAPVGyjZtqfSQ2CRwNrAbxDwi8BqlLhQePOs6d3hqV-3OPLfdE6dUFh2DQ', | ||
nonce: 'lFCnI8.crRTdHfdo5k.zMXfR31856gKz' | ||
}, | ||
function(err, data) { | ||
expect(err).to.be.eql({ | ||
error: 'invalid_token', | ||
errorDescription: 'Invalid access_token' | ||
}); | ||
done(); | ||
} | ||
); // eslint-disable-line | ||
}); | ||
|
||
context('when there is a transaction', function() { | ||
it('should return transaction.appState', function(done) { | ||
|
@@ -824,7 +903,7 @@ describe('auth0.WebAuth', function() { | |
domain: 'mdocs_2.auth0.com', | ||
redirectUri: 'http://example.com/callback', | ||
clientID: '0HP71GSd6PuoRYJ3DXKdiXCUUdGmBbup', | ||
responseType: 'token' | ||
responseType: 'id_token' | ||
}); | ||
|
||
var data = webAuth.parseHash( | ||
|
@@ -880,7 +959,6 @@ describe('auth0.WebAuth', function() { | |
}, | ||
function(err, data) { | ||
expect(err).to.be.eql(expectedError); | ||
WebAuth.prototype.validateToken.restore(); | ||
done(); | ||
} | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters