Skip to content

Commit 0f52cef

Browse files
Simplify AuthenticationResponse.decodeIDToken guard logic
1 parent 70d02d4 commit 0f52cef

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

src/AuthenticationResponse.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,24 +356,25 @@ class AuthenticationResponse {
356356
/**
357357
* decodeIDToken
358358
*
359+
* Note: If the `id_token` is not present in params, this method does not
360+
* get called (short-circuited in `validateIDToken()`).
361+
*
359362
* @param response {AuthenticationResponse}
360363
* @param response.params {object}
361-
* @param response.params.id_token {string} IDToken encoded as a JWT
364+
* @param [response.params.id_token] {string} IDToken encoded as a JWT
362365
*
363366
* @returns {AuthenticationResponse} Chainable
364367
*/
365368
static decodeIDToken (response) {
366369
let jwt = response.params.id_token
367370

368-
if (jwt) {
369-
try {
370-
response.decoded = IDToken.decode(jwt)
371-
} catch (decodeError) {
372-
const error = new HttpError(400, 'Error decoding ID Token')
373-
error.cause = decodeError
374-
error.info = { id_token: jwt }
375-
throw error
376-
}
371+
try {
372+
response.decoded = IDToken.decode(jwt)
373+
} catch (decodeError) {
374+
const error = new HttpError(400, 'Error decoding ID Token')
375+
error.cause = decodeError
376+
error.info = { id_token: jwt }
377+
throw error
377378
}
378379

379380
return response

test/AuthenticationResponseSpec.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,6 @@ describe('AuthenticationResponse', () => {
488488
.should.be.instanceof(JWT)
489489
})
490490

491-
it('should ignore response without id_token', () => {
492-
delete response.params.id_token
493-
expect(AuthenticationResponse.decodeIDToken(response).decoded)
494-
.to.be.undefined()
495-
})
496-
497491
it('should throw an error on invalid id_token', () => {
498492
response.params.id_token = 'inva1id'
499493
expect(() => {

0 commit comments

Comments
 (0)