Added withCredentials request param

This commit is contained in:
Giuseppe Digilio
2019-10-24 15:35:15 +02:00
parent a851a71f22
commit 103425d7ee
2 changed files with 30 additions and 29 deletions

View File

@@ -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.

View File

@@ -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': {