Skip to content

Commit 7c752e5

Browse files
Merge pull request manfredsteyer#339 from NwBankTech/master
Make all of the login functions return Promise<boolean>
2 parents bf279c6 + 1266843 commit 7c752e5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"docs:watch": "npm run docs:build -- -s -w",
1717
"format": "prettier --single-quote --write projects/**/*.ts",
1818
"copy:readme": "cpr README.md dist/lib/README.md --overwrite"
19-
},
19+
},
2020
"private": true,
2121
"dependencies": {
2222
"@angular/animations": "6.0.0",
@@ -49,6 +49,7 @@
4949
"@types/jasminewd2": "~2.0.3",
5050
"@types/node": "~8.0.51",
5151
"codelyzer": "~4.0.1",
52+
"cpr": "^3.0.1",
5253
"jasmine-core": "~2.8.0",
5354
"jasmine-spec-reporter": "~4.2.1",
5455
"karma": "~1.7.1",

projects/lib/src/oauth-service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,15 @@ export class OAuthService extends AuthConfig {
171171
this.restartRefreshTimerIfStillLoggedIn();
172172
}
173173

174+
174175
/**
175176
* Convenience method that first calls `loadDiscoveryDocument(...)` and
176177
* directly chains using the `then(...)` part of the promise to call
177178
* the `tryLogin(...)` method.
178179
*
179180
* @param options LoginOptions to pass through to `tryLogin(...)`
180181
*/
181-
public loadDiscoveryDocumentAndTryLogin(options: LoginOptions = null) {
182+
public loadDiscoveryDocumentAndTryLogin(options: LoginOptions = null): Promise<boolean> {
182183
return this.loadDiscoveryDocument().then(doc => {
183184
return this.tryLogin(options);
184185
});
@@ -191,7 +192,7 @@ export class OAuthService extends AuthConfig {
191192
*
192193
* @param options LoginOptions to pass through to `tryLogin(...)`
193194
*/
194-
public loadDiscoveryDocumentAndLogin(options: LoginOptions = null) {
195+
public loadDiscoveryDocumentAndLogin(options: LoginOptions = null): Promise<boolean> {
195196
return this.loadDiscoveryDocumentAndTryLogin(options).then(_ => {
196197
if (!this.hasValidIdToken() || !this.hasValidAccessToken()) {
197198
this.initImplicitFlow();
@@ -1258,7 +1259,7 @@ export class OAuthService extends AuthConfig {
12581259
*
12591260
* @param options Optional options.
12601261
*/
1261-
public tryLogin(options: LoginOptions = null): Promise<void> {
1262+
public tryLogin(options: LoginOptions = null): Promise<boolean> {
12621263
options = options || {};
12631264

12641265
let parts: object;
@@ -1303,13 +1304,13 @@ export class OAuthService extends AuthConfig {
13031304
}
13041305

13051306
if (this.requestAccessToken && !accessToken) {
1306-
return Promise.resolve();
1307+
return Promise.resolve(false);
13071308
}
13081309
if (this.requestAccessToken && !options.disableOAuth2StateCheck && !state) {
1309-
return Promise.resolve();
1310+
return Promise.resolve(false);
13101311
}
13111312
if (this.oidc && !idToken) {
1312-
return Promise.resolve();
1313+
return Promise.resolve(false);
13131314
}
13141315

13151316
if (this.sessionChecksEnabled && !sessionState) {
@@ -1346,8 +1347,10 @@ export class OAuthService extends AuthConfig {
13461347
if (this.clearHashAfterLogin && !options.preventClearHashAfterLogin) {
13471348
location.hash = '';
13481349
}
1350+
13491351
this.callOnTokenReceivedIfExists(options);
1350-
return Promise.resolve();
1352+
return Promise.resolve(true);
1353+
13511354
}
13521355

13531356
return this.processIdToken(idToken, accessToken)
@@ -1373,6 +1376,7 @@ export class OAuthService extends AuthConfig {
13731376
this.eventsSubject.next(new OAuthSuccessEvent('token_received'));
13741377
this.callOnTokenReceivedIfExists(options);
13751378
this.inImplicitFlow = false;
1379+
return true;
13761380
})
13771381
.catch(reason => {
13781382
this.eventsSubject.next(

0 commit comments

Comments
 (0)