Skip to content

Commit

Permalink
Merge pull request #1000 from damienbod/damein/bugfix-Refresh-respons…
Browse files Browse the repository at this point in the history
…e-without-an-id-token-breaks-mechanism

Bugfix: Refresh response without an id token breaks mechanism
  • Loading branch information
damienbod authored Mar 5, 2021
2 parents e84458f + 29504b0 commit 748bda7
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,26 @@ export class StateValidationService {
return toReturn;
}

const idTokenHeader = this.tokenHelperService.getHeaderFromToken(toReturn.idToken, false);

// The at_hash is optional for the code flow
if (isCurrentFlowCodeFlow && !(toReturn.decodedIdToken.at_hash as string)) {
this.loggerService.logDebug('Code Flow active, and no at_hash in the id_token, skipping check!');
} else if (
!this.tokenValidationService.validateIdTokenAtHash(
toReturn.accessToken,
toReturn.decodedIdToken.at_hash,
idTokenHeader.alg // 'RSA256'
) ||
!toReturn.accessToken
) {
this.loggerService.logWarning('authorizedCallback incorrect at_hash');
toReturn.state = ValidationResult.IncorrectAtHash;
this.handleUnsuccessfulValidation();
return toReturn;
// only do check if id_token returned, no always the case when using refresh tokens
if (callbackContext.authResult.id_token) {
const idTokenHeader = this.tokenHelperService.getHeaderFromToken(toReturn.idToken, false);

// The at_hash is optional for the code flow
if (isCurrentFlowCodeFlow && !(toReturn.decodedIdToken.at_hash as string)) {
this.loggerService.logDebug('Code Flow active, and no at_hash in the id_token, skipping check!');
} else if (
!this.tokenValidationService.validateIdTokenAtHash(
toReturn.accessToken,
toReturn.decodedIdToken.at_hash,
idTokenHeader.alg // 'RSA256'
) ||
!toReturn.accessToken
) {
this.loggerService.logWarning('authorizedCallback incorrect at_hash');
toReturn.state = ValidationResult.IncorrectAtHash;
this.handleUnsuccessfulValidation();
return toReturn;
}
}

toReturn.authResponseIsValid = true;
Expand Down

0 comments on commit 748bda7

Please sign in to comment.