diff --git a/angular-oauth2-oidc/src/oauth-service.ts b/angular-oauth2-oidc/src/oauth-service.ts index d4b5def7..a3f4802c 100644 --- a/angular-oauth2-oidc/src/oauth-service.ts +++ b/angular-oauth2-oidc/src/oauth-service.ts @@ -123,13 +123,7 @@ export class OAuthService } private restartRefreshTimerIfStillLoggedIn(): void { - if (this.hasValidAccessToken()) { - this.setupAccessTokenTimer(); - } - - if (this.hasValidIdToken()) { - this.setupIdTokenTimer(); - } + this.setupExpirationTimers(); } private setupSessionCheck() { @@ -218,16 +212,23 @@ export class OAuthService this.clearAccessTokenTimer(); this.clearIdTokenTimer(); + this.setupExpirationTimers(); - if (this.hasValidAccessToken()) { - this.setupAccessTokenTimer(); - } + }); + } - if (this.hasValidIdToken()) { - this.setupIdTokenTimer(); - } + private setupExpirationTimers(): void { + let idTokenExp = this.getIdTokenExpiration() || Number.MAX_VALUE; + let accessTokenExp = this.getAccessTokenExpiration() || Number.MAX_VALUE; + let useAccessTokenExp = accessTokenExp <= idTokenExp; - }); + if (this.hasValidAccessToken() && useAccessTokenExp ) { + this.setupAccessTokenTimer(); + } + + if (this.hasValidIdToken() && !useAccessTokenExp ) { + this.setupIdTokenTimer(); + } } private setupAccessTokenTimer(): void { @@ -1285,6 +1286,7 @@ export class OAuthService * as milliseconds since 1970. */ public getAccessTokenExpiration(): number { + if (!this._storage.getItem('expires_at')) return null; return parseInt(this._storage.getItem('expires_at'), 10); } @@ -1302,6 +1304,9 @@ export class OAuthService * as milliseconds since 1970. */ public getIdTokenExpiration(): number { + + if (!this._storage.getItem('id_token_expires_at')) return null; + return parseInt(this._storage.getItem('id_token_expires_at'), 10); } diff --git a/angular-oauth2-oidc/src/package.json b/angular-oauth2-oidc/src/package.json index 6aa4022c..ba647333 100644 --- a/angular-oauth2-oidc/src/package.json +++ b/angular-oauth2-oidc/src/package.json @@ -1,6 +1,6 @@ { "name": "angular-oauth2-oidc", - "version": "2.1.2", + "version": "2.1.3", "repository": { "type": "git", "url": "https://github.com/manfredsteyer/angular-oauth2-oidc" diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index d3c0fd8e..00000000 --- a/npm-debug.log +++ /dev/null @@ -1,23 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', -1 verbose cli 'C:\\Users\\Manfred\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js', -1 verbose cli 'run', -1 verbose cli 'docs' ] -2 info using npm@4.0.5 -3 info using node@v6.10.0 -4 verbose stack Error: ENOENT: no such file or directory, open 'C:\Users\Manfred\Documents\bücher\Angular 2\src\oauth-lib4\angular-oauth2-oidc\package.json' -4 verbose stack at Error (native) -5 verbose cwd C:\Users\Manfred\Documents\bücher\Angular 2\src\oauth-lib4\angular-oauth2-oidc -6 error Windows_NT 10.0.10586 -7 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Manfred\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "docs" -8 error node v6.10.0 -9 error npm v4.0.5 -10 error path C:\Users\Manfred\Documents\bücher\Angular 2\src\oauth-lib4\angular-oauth2-oidc\package.json -11 error code ENOENT -12 error errno -4058 -13 error syscall open -14 error enoent ENOENT: no such file or directory, open 'C:\Users\Manfred\Documents\bücher\Angular 2\src\oauth-lib4\angular-oauth2-oidc\package.json' -15 error enoent ENOENT: no such file or directory, open 'C:\Users\Manfred\Documents\bücher\Angular 2\src\oauth-lib4\angular-oauth2-oidc\package.json' -15 error enoent This is most likely not a problem with npm itself -15 error enoent and is related to npm not being able to find a file. -16 verbose exit [ -4058, true ] diff --git a/npm-debug.log.1616803090 b/npm-debug.log.1616803090 deleted file mode 100644 index e69de29b..00000000