|
1 | 1 | import { Injectable } from '@angular/core';
|
2 | 2 | import { Router } from '@angular/router';
|
3 |
| -import { OAuthErrorEvent, OAuthService, OAuthEvent, TokenResponse } from 'angular-oauth2-oidc'; |
| 3 | +import { OAuthErrorEvent, OAuthService } from 'angular-oauth2-oidc'; |
4 | 4 | import { BehaviorSubject, combineLatest, Observable, ReplaySubject } from 'rxjs';
|
5 | 5 | import { filter, map } from 'rxjs/operators';
|
6 | 6 |
|
@@ -106,7 +106,7 @@ export class AuthService {
|
106 | 106 | // 2. SILENT LOGIN:
|
107 | 107 | // Try to log in via a refresh because then we can prevent
|
108 | 108 | // needing to redirect the user:
|
109 |
| - return this.tryNoPromptRefresh() |
| 109 | + return this.oauthService.silentRefresh() |
110 | 110 | .then(() => Promise.resolve())
|
111 | 111 | .catch(result => {
|
112 | 112 | // Subset of situations from https://openid.net/specs/openid-connect-core-1_0.html#AuthError
|
@@ -160,24 +160,14 @@ export class AuthService {
|
160 | 160 | .catch(() => this.isDoneLoadingSubject$.next(true));
|
161 | 161 | }
|
162 | 162 |
|
163 |
| - private tryNoPromptRefresh(): Promise<TokenResponse | OAuthEvent> { |
164 |
| - if (this.oauthService.getRefreshToken()) { |
165 |
| - console.log('Found a refresh token, trying to use it.'); |
166 |
| - return this.oauthService.refreshToken(); |
167 |
| - } |
168 |
| - |
169 |
| - console.log('Found no refresh token, trying iframe based refresh'); |
170 |
| - return this.oauthService.silentRefresh(); |
171 |
| - } |
172 |
| - |
173 | 163 | public login(targetUrl?: string) {
|
174 | 164 | // Note: before version 9.1.0 of the library you needed to
|
175 | 165 | // call encodeURIComponent on the argument to the method.
|
176 | 166 | this.oauthService.initLoginFlow(targetUrl || this.router.url);
|
177 | 167 | }
|
178 | 168 |
|
179 | 169 | public logout() { this.oauthService.logOut(); }
|
180 |
| - public refresh() { this.tryNoPromptRefresh(); } |
| 170 | + public refresh() { this.oauthService.silentRefresh(); } |
181 | 171 | public hasValidToken() { return this.oauthService.hasValidAccessToken(); }
|
182 | 172 |
|
183 | 173 | // These normally won't be exposed from a service like this, but
|
|
0 commit comments