Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTC time #888

Merged
merged 1 commit into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"bugs": {
"url": "https://github.com/damienbod/angular-auth-oidc-client/issues"
},
"version": "11.2.1",
"version": "11.2.2",
"scripts": {
"ng": "ng",
"build": "npm run build-lib",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-auth-oidc-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"authorization"
],
"license": "MIT",
"version": "11.2.1",
"version": "11.2.2",
"description": "Angular Lib for OpenID Connect & OAuth2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('Auth State Service', () => {
const validateAccessTokenNotExpiredResult = true;
const expectedResult = !validateAccessTokenNotExpiredResult;
spyOnProperty(configurationProvider, 'openIDConfiguration', 'get').and.returnValue({ renewTimeBeforeTokenExpiresInSeconds: 5 });
const date = new Date();
const date = new Date(new Date().toUTCString());
spyOn(storagePersistanceService, 'read').withArgs('access_token_expires_at').and.returnValue(date);
const spy = spyOn(tokenValidationService, 'validateAccessTokenNotExpired').and.returnValue(validateAccessTokenNotExpiredResult);
const result = authStateService.hasAccessTokenExpiredIfExpiryExists();
Expand All @@ -265,7 +265,7 @@ describe('Auth State Service', () => {
const validateAccessTokenNotExpiredResult = false;
const expectedResult = !validateAccessTokenNotExpiredResult;
spyOnProperty(configurationProvider, 'openIDConfiguration', 'get').and.returnValue({ renewTimeBeforeTokenExpiresInSeconds: 5 });
const date = new Date();
const date = new Date(new Date().toUTCString());

spyOn(eventsService, 'fireEvent');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class AuthStateService {

private persistAccessTokenExpirationTime(authResult: any) {
if (authResult?.expires_in) {
const accessTokenExpiryTime = new Date().valueOf() + authResult.expires_in * 1000;
const accessTokenExpiryTime = new Date(new Date().toUTCString()).valueOf() + authResult.expires_in * 1000;
this.storagePersistanceService.write('access_token_expires_at', accessTokenExpiryTime);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class TokenHelperService {

getTokenExpirationDate(dataIdToken: any): Date {
if (!dataIdToken.hasOwnProperty('exp')) {
return new Date();
return new Date(new Date().toUTCString());
}

const date = new Date(0); // The 0 here is the key, which sets the date to the epoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class TokenValidationService {
}

const tokenExpirationValue = tokenExpirationDate.valueOf();
const nowWithOffset = new Date().valueOf() + offsetSeconds * 1000;
const nowWithOffset = new Date(new Date().toUTCString()).valueOf() + offsetSeconds * 1000;
const tokenNotExpired = tokenExpirationValue > nowWithOffset;

this.loggerService.logDebug(`Has id_token expired: ${!tokenNotExpired}, ${tokenExpirationValue} > ${nowWithOffset}`);
Expand All @@ -91,7 +91,7 @@ export class TokenValidationService {

offsetSeconds = offsetSeconds || 0;
const accessTokenExpirationValue = accessTokenExpiresAt.valueOf();
const nowWithOffset = new Date().valueOf() + offsetSeconds * 1000;
const nowWithOffset = new Date(new Date().toUTCString()).valueOf() + offsetSeconds * 1000;
const tokenNotExpired = accessTokenExpirationValue > nowWithOffset;

this.loggerService.logDebug(`Has access_token expired: ${!tokenNotExpired}, ${accessTokenExpirationValue} > ${nowWithOffset}`);
Expand Down Expand Up @@ -180,12 +180,12 @@ export class TokenValidationService {

this.loggerService.logDebug(
'validate_id_token_iat_max_offset: ' +
(new Date().valueOf() - dateTimeIatIdToken.valueOf()) +
(new Date(new Date().toUTCString()).valueOf() - dateTimeIatIdToken.valueOf()) +
' < ' +
maxOffsetAllowedInSeconds * 1000
);

const diff = new Date().valueOf() - dateTimeIatIdToken.valueOf();
const diff = new Date(new Date().toUTCString()).valueOf() - dateTimeIatIdToken.valueOf();
if (diff > 0) {
return diff < maxOffsetAllowedInSeconds * 1000;
}
Expand Down