From 103425d7ee9c3fab0499ce4c573b948d727583ac Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 24 Oct 2019 15:35:15 +0200 Subject: [PATCH] Added withCredentials request param --- src/app/core/auth/auth.interceptor.ts | 52 ++++++++++--------- src/app/core/auth/models/auth-method.model.ts | 7 +-- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/app/core/auth/auth.interceptor.ts b/src/app/core/auth/auth.interceptor.ts index 237f6e0820..c8faad4e0c 100644 --- a/src/app/core/auth/auth.interceptor.ts +++ b/src/app/core/auth/auth.interceptor.ts @@ -92,33 +92,37 @@ export class AuthInterceptor implements HttpInterceptor { private parseAuthMethodsfromHeaders(headers: HttpHeaders): AuthMethodModel[] { let authMethodModels: AuthMethodModel[] = []; - const parts: string[] = headers.get('www-authenticate').split(','); - // get the realms from the header - a realm is a single auth method - const completeWWWauthenticateHeader = headers.get('www-authenticate'); - const regex = /(\w+ (\w+=((".*?")|[^,]*)(, )?)*)/g; - const realms = completeWWWauthenticateHeader.match(regex); + if (isNotEmpty(headers.get('www-authenticate'))) { + const parts: string[] = headers.get('www-authenticate').split(','); + // get the realms from the header - a realm is a single auth method + const completeWWWauthenticateHeader = headers.get('www-authenticate'); + const regex = /(\w+ (\w+=((".*?")|[^,]*)(, )?)*)/g; + const realms = completeWWWauthenticateHeader.match(regex); - // tslint:disable-next-line:forin - for (const j in realms) { + // tslint:disable-next-line:forin + for (const j in realms) { - const splittedRealm = realms[j].split(', '); - const methodName = splittedRealm[0].split(' ')[0].trim(); + const splittedRealm = realms[j].split(', '); + const methodName = splittedRealm[0].split(' ')[0].trim(); - let authMethodModel: AuthMethodModel; - if (splittedRealm.length === 1) { - authMethodModel = new AuthMethodModel(methodName); - authMethodModels.push(authMethodModel); - } else if (splittedRealm.length > 1) { - let location = splittedRealm[1]; - location = this.parseLocation(location); - authMethodModel = new AuthMethodModel(methodName, location); - // console.log('location: ', location); - authMethodModels.push(authMethodModel); + let authMethodModel: AuthMethodModel; + if (splittedRealm.length === 1) { + authMethodModel = new AuthMethodModel(methodName); + authMethodModels.push(authMethodModel); + } else if (splittedRealm.length > 1) { + let location = splittedRealm[1]; + location = this.parseLocation(location); + authMethodModel = new AuthMethodModel(methodName, location); + // console.log('location: ', location); + authMethodModels.push(authMethodModel); + } } - } - // make sure the email + password login component gets rendered first - authMethodModels = this.sortAuthMethods(authMethodModels); + // make sure the email + password login component gets rendered first + authMethodModels = this.sortAuthMethods(authMethodModels); + } else { + authMethodModels.push(new AuthMethodModel(AuthMethodType.Password)); + } return authMethodModels; } @@ -172,9 +176,9 @@ export class AuthInterceptor implements HttpInterceptor { // Get the auth header from the service. const Authorization = authService.buildAuthHeader(token); // Clone the request to add the new header. - newReq = req.clone({headers: req.headers.set('authorization', Authorization)}); + newReq = req.clone({headers: req.headers.set('authorization', Authorization), withCredentials: true}); } else { - newReq = req; + newReq = req.clone({withCredentials: true}); } // Pass on the new request instead of the original request. diff --git a/src/app/core/auth/models/auth-method.model.ts b/src/app/core/auth/models/auth-method.model.ts index 131150e457..76b9f51aea 100644 --- a/src/app/core/auth/models/auth-method.model.ts +++ b/src/app/core/auth/models/auth-method.model.ts @@ -1,9 +1,9 @@ import { AuthMethodType } from '../../../shared/log-in/methods/authMethods-type'; -import { ShibbConstants } from '../../../+login-page/shibbolethTargetPage/const/shibbConstants'; export class AuthMethodModel { authMethodType: AuthMethodType; location?: string; + // isStandalonePage? = true; constructor(authMethodName: string, location?: string) { @@ -18,10 +18,7 @@ export class AuthMethodModel { } case 'shibboleth': { this.authMethodType = AuthMethodType.Shibboleth; - // const strings: string[] = location.split('target='); - // const target = strings[1]; - // this.location = target + location + '/' + ShibbConstants.SHIBBOLETH_REDIRECT_ROUTE; - this.location = location + '/' + ShibbConstants.SHIBBOLETH_REDIRECT_ROUTE; + this.location = location; break; } case 'x509': {