forked from hazza/dspace-angular
Added method getLocationFromHeaders() to auth.interceptor
This commit is contained in:
@@ -5,7 +5,7 @@ import {Injectable, Injector} from '@angular/core';
|
|||||||
import {
|
import {
|
||||||
HttpErrorResponse,
|
HttpErrorResponse,
|
||||||
HttpEvent,
|
HttpEvent,
|
||||||
HttpHandler,
|
HttpHandler, HttpHeaders,
|
||||||
HttpInterceptor,
|
HttpInterceptor,
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
@@ -77,6 +77,19 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||||||
return authStatus;
|
return authStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getLocationfromHeader(header: HttpHeaders): string {
|
||||||
|
console.log('HEADER www-authenticate: ', header.get('www-authenticate'));
|
||||||
|
let location = '';
|
||||||
|
if (header.get('www-authenticate').startsWith('shibboleth realm')) {
|
||||||
|
const strings = header.get('www-authenticate').split(',');
|
||||||
|
location = strings[1];
|
||||||
|
location = location.replace('location=', '');
|
||||||
|
console.log('This should be the location: ', location);
|
||||||
|
return location = location.replace('"', '').trim();
|
||||||
|
}
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
|
|
||||||
const authService = this.inj.get(AuthService);
|
const authService = this.inj.get(AuthService);
|
||||||
@@ -139,30 +152,17 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||||||
if (error instanceof HttpErrorResponse) {
|
if (error instanceof HttpErrorResponse) {
|
||||||
|
|
||||||
// Check for 405
|
// Check for 405
|
||||||
if (this.is405AuthResponse(error)) {
|
/* if (this.is405AuthResponse(error)) {
|
||||||
console.log('the caught error is a 405');
|
console.log('the caught error is a 405');
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Checks if is a response from a request to an authentication endpoint
|
// Checks if is a response from a request to an authentication endpoint
|
||||||
if (this.isAuthRequest(error)) {
|
if (this.isAuthRequest(error)) {
|
||||||
console.log('catchError isAuthRequest=true');
|
console.log('catchError isAuthRequest=true');
|
||||||
// clean eventually refresh Requests list
|
// clean eventually refresh Requests list
|
||||||
|
|
||||||
this.refreshTokenRequestUrls = [];
|
this.refreshTokenRequestUrls = [];
|
||||||
// console.log('error: ', error);
|
// console.log('error: ', error);
|
||||||
let location = error.headers.get('location');// this line added while shibboleth dev
|
const location = this.getLocationfromHeader(error.headers);
|
||||||
console.log('error.headers.get("location"): ', location);
|
|
||||||
|
|
||||||
console.log('www-authenticate', error.headers.get('www-authenticate'));
|
|
||||||
const strings = error.headers.get('www-authenticate').split(',');
|
|
||||||
const locationstring = strings[1];
|
|
||||||
const s = locationstring.replace('location=', '');
|
|
||||||
const s1 = s.replace('"', '').trim();
|
|
||||||
console.log('This should be the location: ', s1);
|
|
||||||
location = s1;
|
|
||||||
|
|
||||||
console.log('error headers: ', error.headers);
|
|
||||||
console.log('error', error);
|
|
||||||
|
|
||||||
// Create a new HttpResponse and return it, so it can be handle properly by AuthService.
|
// Create a new HttpResponse and return it, so it can be handle properly by AuthService.
|
||||||
const authResponse = new HttpResponse({
|
const authResponse = new HttpResponse({
|
||||||
|
@@ -209,7 +209,7 @@ export class AuthService {
|
|||||||
let url = '';
|
let url = '';
|
||||||
if (isNotEmpty(status.ssoLoginUrl)) {
|
if (isNotEmpty(status.ssoLoginUrl)) {
|
||||||
// url = this.parseSSOLocation(status.ssoLoginUrl);
|
// url = this.parseSSOLocation(status.ssoLoginUrl);
|
||||||
url = 'https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login?target=https%3A%2F%2Ffis.tiss.tuwien.ac.at';
|
url = 'https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login?target=https://fis.tiss.tuwien.ac.at';
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user