diff --git a/src/app/auth.config.ts b/src/app/auth.config.ts index 537fd9b..3416eab 100644 --- a/src/app/auth.config.ts +++ b/src/app/auth.config.ts @@ -23,8 +23,8 @@ export const authConfig: AuthConfig = { // Important: Request offline_access to get a refresh token // The api scope is a usecase specific one scope: useSilentRefreshForCodeFlow - ? 'openid profile email api' - : 'openid profile email offline_access api', + ? 'openid profile email' + : 'openid profile email offline_access', // ^^ Please note that offline_access is not needed for silent refresh // At least when using idsvr, this even prevents silent refresh diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 102fa84..a96f0ee 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -14,18 +14,23 @@ export class HeaderComponent implements OnInit { async login(): Promise { this.oauthService.configure(authConfig); - await this.oauthService.loadDiscoveryDocumentAndTryLogin().then((_) => { - console.log( - 'LOGGED=' + (this.oauthService.hasValidIdToken() - && this.oauthService.hasValidAccessToken()) - ); - }); + await this.oauthService.loadDiscoveryDocument(); + if ( + !this.oauthService.hasValidIdToken() || + !this.oauthService.hasValidAccessToken() + ) { + this.oauthService.initLoginFlow('some-state'); + } } logout(): void { this.oauthService.revokeTokenAndLogout(); } + get logged(): boolean { + return this.oauthService.getIdentityClaims() != null; + } + get name(): any { const claims = this.oauthService.getIdentityClaims(); if (!claims) { diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 43b34ad..6322cee 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,37 +1,6 @@

Mis viajes

- -

Logueate para ver tus viajes

+ +

Logueate para ver tus viajes

Viajes disponibles

- -

Login={{login}} loginFailed={{loginFailed}}

- -
-
-

access_token_expiration: {{ access_token_expiration }}

-

id_token_expiration: {{ id_token_expiration }}

-
-
- -
-
-

access_token: {{ access_token }}

-

id_token: {{ id_token }}

-
- user profile: -
{{ userProfile | json }}
-
-
-
- -
-
-

Further Actions

- - - -
-
diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 6c60a4a..3e099be 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -59,40 +59,7 @@ export class HomeComponent implements OnInit { } } - set requestAccessToken(value: boolean) { - this.oauthService.requestAccessToken = value; - localStorage.setItem('requestAccessToken', '' + value); - } - - get requestAccessToken(): boolean { - return this.oauthService.requestAccessToken; - } - - set useHashLocationStrategy(value: boolean) { - const oldValue = localStorage.getItem('useHashLocationStrategy') === 'true'; - if (value !== oldValue) { - localStorage.setItem('useHashLocationStrategy', value ? 'true' : 'false'); - window.location.reload(); - } - } - - get useHashLocationStrategy(): boolean { - return localStorage.getItem('useHashLocationStrategy') === 'true'; - } - - get id_token(): string { - return this.oauthService.getIdToken(); - } - - get access_token(): string { - return this.oauthService.getAccessToken(); - } - - get id_token_expiration(): number { - return this.oauthService.getIdTokenExpiration(); - } - - get access_token_expiration(): number { - return this.oauthService.getAccessTokenExpiration(); + get logged(): boolean { + return this.oauthService.hasValidIdToken() && this.oauthService.hasValidAccessToken(); } } diff --git a/src/app/services/api.service.ts b/src/app/services/api.service.ts index 38969a6..ad67dc5 100644 --- a/src/app/services/api.service.ts +++ b/src/app/services/api.service.ts @@ -17,7 +17,7 @@ export class ApiService { return this.http .get>(url, { params }) .pipe( - retry(3), // retry a failed request up to 3 times + retry(0), // retry a failed request up to 3 times catchError(this.handleError) // then handle the error ); }