Skip to content

Commit

Permalink
Don't validate access_token when there is no payload.at_hash claim (#718
Browse files Browse the repository at this point in the history
)
  • Loading branch information
luisrudge authored Mar 22, 2018
1 parent 0ab40ac commit 8108dbb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/web-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ WebAuth.prototype.validateAuthenticationResponse = function(options, parsedHash,
if (!parsedHash.access_token) {
return callback(null, payload);
}
// id_token's generated by non-oidc clients don't have at_hash
if (!payload.at_hash) {
return callback(null, payload);
}
// here we're absolutely sure that the id_token's alg is RS256
// and that the id_token is valid, so we can check the access_token
return new IdTokenVerifier().validateAccessToken(
Expand Down
54 changes: 54 additions & 0 deletions test/web-auth/web-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,60 @@ describe('auth0.WebAuth', function() {
}
); // eslint-disable-line
});
it('should return the id_token payload when there is no payload.at_hash', function(done) {
var webAuth = new WebAuth({
domain: 'brucke.auth0.com',
redirectUri: 'http://example.com/callback',
clientID: 'BWDP9XS89CJq1w6Nzq7iFOHsTh6ChS2b',
responseType: 'id_token',
__disableExpirationCheck: true
});

var data = webAuth.parseHash(
{
hash: '#state=foo&token_type=Bearer&access_token=AiU65szv2vyh2xpom8Dqbkdwok4RRZkx&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5FVkJOVU5CT1RneFJrRTVOa1F6UXpjNE9UQkVNRUZGUkRRNU4wUTJRamswUmtRMU1qRkdNUSJ9.eyJlbWFpbCI6ImpvaG5mb29AZ21haWwuY29tIiwidXNlcm5hbWUiOiJqb2huZm9vIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJ1c2VyX2lkIjoiYXV0aDB8NWEyMDU0ZmY0NTE1NzcxMWJlODE4MmY0IiwiY2xpZW50SUQiOiJCV0RQOVhTODlDSnExdzZOenE3aUZPSHNUaDZDaFMy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AzMjIsImV4cCI6MTUyMTc5NjMyMn0.b1afXXSurcVvg71-9w0ABhxLfP5FCdSEPPDYqD8pj2yJXxdVbyK3kdd-caldW330FKwpJlibIbcT4Mz1EpkM_M4P7OyNb1_dJbEgXFoIyqshI4YyIOC0Hn95GPE4uBZMR4GH6O32Scw3KQl9M_pQOZrQySLvU-XNs0Ko99soZbivoc-HTLEXiHDEk9mmnQOBcz44XayMieLP5WQ3c-dDShpFw-Y-8QaaQr1WI1ailh_UdJeJq6SUdn4ItTPUWf7uhmDcWQPJyWh6MyHWBoL4iWh4ZEliVG8Js8J00higeoqP7rsrymb_Hvz5f801mzpro72zfar_tVMp144mH8A65g',
idTokenPayload: {
email: 'johnfoo@gmail.com',
username: 'johnfoo',
email_verified: false,
user_id: 'auth0|5a2054ff45157711be8182f4',
clientID: 'BWDP9XS89CJq1w6Nzq7iFOHsTh6ChS2b',
picture: 'https://s.gravatar.com/avatar/38fa002423bd8c941c6ed0588b60ffed?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fjo.png',
nickname: 'johnfoo',
identities: [
{
user_id: '5a2054ff45157711be8182f4',
provider: 'auth0',
connection: 'acme',
isSocial: false
}
],
updated_at: '2018-03-22T23:12:02.575Z',
created_at: '2017-11-30T18:59:11.368Z',
name: 'johnfoo@gmail.com',
iss: 'https://brucke.auth0.com/',
sub: 'auth0|5a2054ff45157711be8182f4',
aud: 'BWDP9XS89CJq1w6Nzq7iFOHsTh6ChS2b',
iat: 1521760322,
exp: 1521796322
},
appState: null,
refreshToken: null,
state: 'foo',
expiresIn: null,
tokenType: 'Bearer',
scope: null
});
done();
}
); // eslint-disable-line
});
it('should return the id_token payload when there is a valid access_token', function(done) {
var webAuth = new WebAuth({
domain: 'brucke.auth0.com',
Expand Down

0 comments on commit 8108dbb

Please sign in to comment.