diff --git a/src/app/_interceptors/error.interceptor.ts b/src/app/_interceptors/error.interceptor.ts index a6ee321..2f53f1b 100644 --- a/src/app/_interceptors/error.interceptor.ts +++ b/src/app/_interceptors/error.interceptor.ts @@ -54,7 +54,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 e703bfa..63982fd 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -46,8 +46,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', }; @@ -91,36 +92,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 2981c63..a51d47e 100644 --- a/src/app/auth/auth.component.ts +++ b/src/app/auth/auth.component.ts @@ -57,7 +57,7 @@ export class AuthComponent implements OnInit { } } catch (HttpError) { this.errorDialogService.openDialog({ - message: HttpError.message, + message: "Failed to login please try again.", }); } }