From 700a468c4f8280cbf59484b0529be66d69e441b3 Mon Sep 17 00:00:00 2001 From: Adam Pierson Date: Wed, 30 May 2018 09:33:21 -0600 Subject: [PATCH 1/3] Updated all trylogin functions to return Promise to indicate if login was a success --- .gitignore | 3 +++ projects/lib/src/oauth-service.ts | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index ee5c9d83..ab5b63ea 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ testem.log # System Files .DS_Store Thumbs.db + +.ng_pkg_build +node_modules diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 7ef9e7f0..e4a628fc 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -167,13 +167,13 @@ export class OAuthService extends AuthConfig { this.restartRefreshTimerIfStillLoggedIn(); } - public loadDiscoveryDocumentAndTryLogin(options: LoginOptions = null) { + public loadDiscoveryDocumentAndTryLogin(options: LoginOptions = null): Promise { return this.loadDiscoveryDocument().then(doc => { return this.tryLogin(options); }); } - public loadDiscoveryDocumentAndLogin(options: LoginOptions = null) { + public loadDiscoveryDocumentAndLogin(options: LoginOptions = null): Promise { return this.loadDiscoveryDocumentAndTryLogin(options).then(_ => { if (!this.hasValidIdToken() || !this.hasValidAccessToken()) { this.initImplicitFlow(); @@ -331,14 +331,14 @@ export class OAuthService extends AuthConfig { /** * DEPRECATED. Use a provider for OAuthStorage instead: - * + * * { provide: OAuthStorage, useValue: localStorage } - * + * * Sets a custom storage used to store the received * tokens on client side. By default, the browser's * sessionStorage is used. * @ignore - * + * * @param storage */ public setStorage(storage: OAuthStorage): void { @@ -845,7 +845,7 @@ export class OAuthService extends AuthConfig { const redirectUri = this.silentRefreshRedirectUri || this.redirectUri; this.createLoginUrl(null, null, redirectUri, noPrompt, params).then(url => { iframe.setAttribute('src', url); - + if (!this.silentRefreshShowIFrame) { iframe.style['display'] = 'none'; } @@ -1247,7 +1247,7 @@ export class OAuthService extends AuthConfig { * * @param options Optinal options. */ - public tryLogin(options: LoginOptions = null): Promise { + public tryLogin(options: LoginOptions = null): Promise { options = options || {}; let parts: object; @@ -1292,13 +1292,13 @@ export class OAuthService extends AuthConfig { } if (this.requestAccessToken && !accessToken) { - return Promise.resolve(); + return Promise.resolve(false); } if (this.requestAccessToken && !options.disableOAuth2StateCheck && !state) { - return Promise.resolve(); + return Promise.resolve(false); } if (this.oidc && !idToken) { - return Promise.resolve(); + return Promise.resolve(false); } if (this.sessionChecksEnabled && !sessionState) { @@ -1335,7 +1335,7 @@ export class OAuthService extends AuthConfig { if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) { location.hash = ''; } - return Promise.resolve(); + return Promise.resolve(true); } return this.processIdToken(idToken, accessToken) @@ -1361,6 +1361,7 @@ export class OAuthService extends AuthConfig { this.eventsSubject.next(new OAuthSuccessEvent('token_received')); this.callOnTokenReceivedIfExists(options); this.inImplicitFlow = false; + return true; }) .catch(reason => { this.eventsSubject.next( From 04f8a396faa4c670f893a2cf23203923f419e45b Mon Sep 17 00:00:00 2001 From: Adam Pierson Date: Wed, 30 May 2018 16:28:51 -0600 Subject: [PATCH 2/3] reverted to previous .gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index ab5b63ea..ee5c9d83 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,3 @@ testem.log # System Files .DS_Store Thumbs.db - -.ng_pkg_build -node_modules From 4d2e48aaf2bd32a3d2d5f68f6d47c4cfd3c36b5c Mon Sep 17 00:00:00 2001 From: Adam Pierson Date: Thu, 31 May 2018 10:54:05 -0600 Subject: [PATCH 3/3] added cpr as a dev dependency since it's used in the build --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d0735f5c..306087c6 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "docs:watch": "npm run docs:build -- -s -w", "format": "prettier --single-quote --write projects/**/*.ts", "copy:readme": "cpr README.md dist/lib/README.md --overwrite" - }, + }, "private": true, "dependencies": { "@angular/animations": "6.0.0", @@ -49,6 +49,7 @@ "@types/jasminewd2": "~2.0.3", "@types/node": "~8.0.51", "codelyzer": "~4.0.1", + "cpr": "^3.0.1", "jasmine-core": "~2.8.0", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1",