Skip to content

Commit

Permalink
Merge pull request #1451 from L1nkss/disable-id-token-validation
Browse files Browse the repository at this point in the history
Disable id_token time validation
  • Loading branch information
damienbod authored Jun 1, 2022
2 parents c6270d3 + 192d97f commit c956df4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ describe('Auth State Service', () => {

authStateService.hasIdTokenExpiredAndRenewCheckIsEnabled(config);

expect(spy).toHaveBeenCalledOnceWith('idToken', config, 30);
expect(spy).toHaveBeenCalledOnceWith('idToken', config, 30, undefined);
});

it('fires event if idToken is expired', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ export class AuthStateService {
}

hasIdTokenExpiredAndRenewCheckIsEnabled(configuration: OpenIdConfiguration): boolean {
const { renewTimeBeforeTokenExpiresInSeconds, enableIdTokenExpiredValidationInRenew } = configuration;
const { renewTimeBeforeTokenExpiresInSeconds, enableIdTokenExpiredValidationInRenew, disableIdTokenValidation } = configuration;

if (!enableIdTokenExpiredValidationInRenew) {
return false;
}
const tokenToCheck = this.storagePersistenceService.getIdToken(configuration);

const idTokenExpired = this.tokenValidationService.hasIdTokenExpired(tokenToCheck, configuration, renewTimeBeforeTokenExpiresInSeconds);
const idTokenExpired = this.tokenValidationService.hasIdTokenExpired(tokenToCheck, configuration, renewTimeBeforeTokenExpiresInSeconds, disableIdTokenValidation);

if (idTokenExpired) {
this.publicEventsService.fireEvent<boolean>(EventTypes.IdTokenExpired, idTokenExpired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,6 @@ export interface OpenIdConfiguration {
* The refresh token rotation is optional (rfc6749) but is more safe and hence encouraged.
*/
allowUnsafeReuseRefreshToken?: boolean;
/** Disable validation for id_token expiry time */
disableIdTokenValidation?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class StateValidationService {
}

if (callbackContext.authResult.id_token) {
const { clientId, issValidationOff, maxIdTokenIatOffsetAllowedInSeconds, disableIatOffsetValidation, ignoreNonceAfterRefresh } =
const { clientId, issValidationOff, maxIdTokenIatOffsetAllowedInSeconds, disableIatOffsetValidation, ignoreNonceAfterRefresh, disableIdTokenValidation } =
configuration;

toReturn.idToken = callbackContext.authResult.id_token;
Expand Down Expand Up @@ -164,7 +164,7 @@ export class StateValidationService {
return of(toReturn);
}

if (!this.tokenValidationService.validateIdTokenExpNotExpired(toReturn.decodedIdToken, configuration)) {
if (!this.tokenValidationService.validateIdTokenExpNotExpired(toReturn.decodedIdToken, configuration, maxIdTokenIatOffsetAllowedInSeconds, disableIdTokenValidation)) {
this.loggerService.logWarning(configuration, 'authCallback id token expired');
toReturn.state = ValidationResult.TokenExpired;
this.handleUnsuccessfulValidation(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ export class TokenValidationService {

// id_token C7: The current time MUST be before the time represented by the exp Claim
// (possibly allowing for some small leeway to account for clock skew).
hasIdTokenExpired(token: string, configuration: OpenIdConfiguration, offsetSeconds?: number): boolean {
hasIdTokenExpired(token: string, configuration: OpenIdConfiguration, offsetSeconds?: number, disableIdTokenValidation?: boolean): boolean {
const decoded = this.tokenHelperService.getPayloadFromToken(token, false, configuration);

return !this.validateIdTokenExpNotExpired(decoded, configuration, offsetSeconds);
return !this.validateIdTokenExpNotExpired(decoded, configuration, offsetSeconds, disableIdTokenValidation);
}

// id_token C7: The current time MUST be before the time represented by the exp Claim
// (possibly allowing for some small leeway to account for clock skew).
validateIdTokenExpNotExpired(decodedIdToken: string, configuration: OpenIdConfiguration, offsetSeconds?: number): boolean {
validateIdTokenExpNotExpired(decodedIdToken: string, configuration: OpenIdConfiguration, offsetSeconds?: number, disableIdTokenValidation?: boolean): boolean {
if (disableIdTokenValidation) return true;

const tokenExpirationDate = this.tokenHelperService.getTokenExpirationDate(decodedIdToken);
offsetSeconds = offsetSeconds || 0;

Expand Down

0 comments on commit c956df4

Please sign in to comment.