From 09c45aa2e55007ba49cfb12b1555be5e40d55999 Mon Sep 17 00:00:00 2001 From: Blair Vanderlugt Date: Wed, 30 Jun 2021 08:53:31 -0700 Subject: [PATCH] messages --- src/app/_interceptors/error.interceptor.ts | 4 ++- src/app/_services/auth.service.ts | 41 +++++++++++----------- src/app/auth/auth.component.ts | 2 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/app/_interceptors/error.interceptor.ts b/src/app/_interceptors/error.interceptor.ts index 31e3812..e189d9b 100644 --- a/src/app/_interceptors/error.interceptor.ts +++ b/src/app/_interceptors/error.interceptor.ts @@ -59,7 +59,9 @@ export class ErrorInterceptor implements HttpInterceptor { this.router.navigateByUrl('/auth').then(); break; case 403: // forbidden - alert('Access to resource is not allowed!'); + this.errorDialogService.openDialog( + { message: 'Access to resource is not allowed (Error 403)'}) + //alert('Access to resource is not allowed!'); break; } // Return an observable with a user-facing error message. diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index 1022f54..53e3d13 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -48,8 +48,9 @@ export class AuthService { } getWithToken(): Promise { + const sessionToken = this.getSessionToken() const headers = { - Authorization: 'Bearer ' + this.getSessionToken, + Authorization: 'Bearer ' + sessionToken, 'Content-Type': 'application/json;charset=utf-8', 'x-cic-automerge': 'none', }; @@ -93,36 +94,36 @@ export class AuthService { async login(): Promise { if (this.getSessionToken()) { sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN')); - } else { - const o = await this.getChallenge(); + } + const o = await this.getChallenge(); - const r = await signChallenge( - o.challenge, - o.realm, - environment.cicMetaUrl, - this.mutableKeyStore - ); + const r = await signChallenge( + o.challenge, + o.realm, + environment.cicMetaUrl, + this.mutableKeyStore + ); - const tokenResponse = await this.sendSignedChallenge(r).then((response) => { + const tokenResponse = await this.sendSignedChallenge(r) + .then((response) => { const token = response.headers.get('Token'); if (token) { - return token; + return token; } if (response.status === 401) { - throw new HttpError('You are not authorized to use this system', response.status); + throw new HttpError('You are not authorized to use this system', response.status); } if (!response.ok) { - throw new HttpError('Unknown error from authentication server', response.status); + throw new HttpError('Unknown error from authentication server', response.status); } - }); + }); - if (tokenResponse) { - this.setSessionToken(tokenResponse); - this.setState('Click button to log in'); - return true; - } - return false; + if (tokenResponse) { + this.setSessionToken(tokenResponse); + //this.setState('Click button to log in'); + return true; } + return false; } loginView(): void { diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts index 5c507f3..d715fd4 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -58,7 +58,7 @@ export class AuthComponent implements OnInit { } } catch (HttpError) { this.errorDialogService.openDialog({ - message: HttpError.message, + message: "Failed to login please try again.", }); } }