From de0ae01fb2adcbb38fa5817c2c629da85b070415 Mon Sep 17 00:00:00 2001 From: Eneko Date: Mon, 22 Mar 2021 18:59:37 +0100 Subject: [PATCH] Prueba fallida con checkAuthIncludingServer() --- src/app/auth/auth-config.module.ts | 7 ++++--- src/app/services/auth.service.ts | 27 +++++++++++++++++---------- src/silent-renew.html | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 src/silent-renew.html diff --git a/src/app/auth/auth-config.module.ts b/src/app/auth/auth-config.module.ts index 3e1a213..2a6640b 100644 --- a/src/app/auth/auth-config.module.ts +++ b/src/app/auth/auth-config.module.ts @@ -11,15 +11,16 @@ export function configureAuth(oidcConfigService: OidcConfigService): () => Promi redirectUrl: window.location.origin, postLogoutRedirectUri: window.location.origin, clientId: 'okupamicoche-frontend-angular', - scope: 'openid profile offline_access', + scope: 'openid profile', responseType: 'code', silentRenew: true, - useRefreshToken: true, + // useRefreshToken: true, + silentRenewUrl: `${window.location.origin}/silent-renew.html`, renewTimeBeforeTokenExpiresInSeconds: 30, tokenRefreshInSeconds: 20, ignoreNonceAfterRefresh: true, // El refresh token está fallando si no se ignora el Nonce secureRoutes: [TRAVEL_API_URL, USER_API_URL], - storage: localStorage, + // storage: localStorage, logLevel: LogLevel.Warn }); } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 4b483ee..38372af 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -53,13 +53,12 @@ export class AuthService { this.userSubject.next(User.fromClaims(claims)); }); - return this.oidcSecurityService.checkAuth().toPromise().then((auth) => { - console.log('AUTH INITIALIZED result=', auth); - - if (auth) { - if (sessionStorage.getItem('chatLoginInProcess') === 'true') { - sessionStorage.removeItem('chatLoginInProcess'); + if ((sessionStorage.getItem('chatLoginInProcess') === 'true') || chatLoginToken) { + sessionStorage.removeItem('chatLoginInProcess'); + return this.oidcSecurityService.checkAuth().toPromise().then((auth) => { + console.log('AUTH INITIALIZED result=', auth); + if (auth) { if (chatLoginToken) { console.log('chatLoginToken=' + chatLoginToken); this.chatService.login(chatLoginToken); @@ -73,15 +72,23 @@ export class AuthService { return AuthState.Logged; } - else { + + return AuthState.NotLogged; + }); + } + else { + return this.oidcSecurityService.checkAuthIncludingServer().toPromise().then((auth) => { + console.log('AUTH INITIALIZED result=', auth); + + if (auth) { console.log('GO TO SSO LOGIN'); sessionStorage.setItem('chatLoginInProcess', 'true'); this.chatService.goToSsoLogin(); return AuthState.ChatLoggingInProcess; } - } - return AuthState.NotLogged; - }); + return AuthState.NotLogged; + }); + } } } diff --git a/src/silent-renew.html b/src/silent-renew.html new file mode 100644 index 0000000..c12ec2b --- /dev/null +++ b/src/silent-renew.html @@ -0,0 +1,21 @@ + + + + + + + silent-renew + + + + + + \ No newline at end of file