diff --git a/config/environment.default.js b/config/environment.default.js index f0cf41b037..f13cbcfc74 100644 --- a/config/environment.default.js +++ b/config/environment.default.js @@ -32,8 +32,8 @@ module.exports = { // Authentications auth: { target: { - host: 'https://dspace7.4science.it', - page: '/dspace-spring-rest/shib.html' + host: 'https://fis.tiss.tuwien.ac.at', + page: '/spring-rest/login.html' } }, // Form settings diff --git a/src/app/core/auth/auth.interceptor.ts b/src/app/core/auth/auth.interceptor.ts index 1a7acb805f..f74ff6e878 100644 --- a/src/app/core/auth/auth.interceptor.ts +++ b/src/app/core/auth/auth.interceptor.ts @@ -1,7 +1,7 @@ -import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs'; +import {Observable, of as observableOf, throwError as observableThrowError} from 'rxjs'; -import { catchError, filter, map } from 'rxjs/operators'; -import { Injectable, Injector } from '@angular/core'; +import {catchError, filter, map} from 'rxjs/operators'; +import {Injectable, Injector} from '@angular/core'; import { HttpErrorResponse, HttpEvent, @@ -11,16 +11,16 @@ import { HttpResponse, HttpResponseBase } from '@angular/common/http'; -import { find } from 'lodash'; +import {find} from 'lodash'; -import { AppState } from '../../app.reducer'; -import { AuthService } from './auth.service'; -import { AuthStatus } from './models/auth-status.model'; -import { AuthTokenInfo } from './models/auth-token-info.model'; -import { isNotEmpty, isUndefined, isNotNull } from '../../shared/empty.util'; -import { RedirectWhenTokenExpiredAction, RefreshTokenAction } from './auth.actions'; -import { Store } from '@ngrx/store'; -import { Router } from '@angular/router'; +import {AppState} from '../../app.reducer'; +import {AuthService} from './auth.service'; +import {AuthStatus} from './models/auth-status.model'; +import {AuthTokenInfo} from './models/auth-token-info.model'; +import {isNotEmpty, isUndefined, isNotNull} from '../../shared/empty.util'; +import {RedirectWhenTokenExpiredAction, RefreshTokenAction} from './auth.actions'; +import {Store} from '@ngrx/store'; +import {Router} from '@angular/router'; import {AuthError} from './models/auth-error.model'; @Injectable() @@ -31,7 +31,8 @@ export class AuthInterceptor implements HttpInterceptor { // we're creating a refresh token request list protected refreshTokenRequestUrls = []; - constructor(private inj: Injector, private router: Router, private store: Store) { } + constructor(private inj: Injector, private router: Router, private store: Store) { + } private is405AuthResponse(response: HttpResponseBase): boolean { return response.status === 405; @@ -61,7 +62,7 @@ export class AuthInterceptor implements HttpInterceptor { return http.url && http.url.endsWith('/authn/logout'); } - private makeAuthStatusObject(authenticated:boolean, accessToken?: string, error?: string, location?: string): AuthStatus { + private makeAuthStatusObject(authenticated: boolean, accessToken?: string, error?: string, location?: string): AuthStatus { const authStatus = new AuthStatus(); authStatus.id = null; authStatus.okay = true; @@ -146,10 +147,19 @@ export class AuthInterceptor implements HttpInterceptor { if (this.isAuthRequest(error)) { console.log('catchError isAuthRequest=true'); // clean eventually refresh Requests list + this.refreshTokenRequestUrls = []; // console.log('error: ', error); - const location = error.headers.get('Location');// this line added while shibboleth dev - console.log('error.headers.get("Location"): ', location); + let location = error.headers.get('location');// this line added while shibboleth dev + console.log('error.headers.get("location"): ', location); + + console.log('www-authenticate', error.headers.get('www-authenticate')); + let strings = error.headers.get('www-authenticate').split(','); + let string = strings[1]; + let s = string.replace('location=', ''); + let s1 = s.replace('"', '').trim(); + console.log('This should be the location: ', s1); + location = s1; console.log('error headers: ', error.headers); console.log('error', error); diff --git a/src/app/core/auth/auth.service.spec.ts b/src/app/core/auth/auth.service.spec.ts index e766a45e48..c15d123783 100644 --- a/src/app/core/auth/auth.service.spec.ts +++ b/src/app/core/auth/auth.service.spec.ts @@ -23,6 +23,8 @@ import { AppState } from '../../app.reducer'; import { ClientCookieService } from '../../shared/services/client-cookie.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { getMockRemoteDataBuildService } from '../../shared/mocks/mock-remote-data-build.service'; +import {GlobalConfig} from '../../../config/global-config.interface'; +import {GLOBAL_CONFIG} from '../../../config'; describe('AuthService test', () => { @@ -138,9 +140,9 @@ describe('AuthService test', () => { { provide: AuthRequestService, useValue: authRequest }, { provide: REQUEST, useValue: {} }, { provide: Router, useValue: routerStub }, - { provide: RemoteDataBuildService, useValue: rdbService }, + CookieService, - AuthService + AuthService, ] }).compileComponents(); })); @@ -151,7 +153,7 @@ describe('AuthService test', () => { (state as any).core = Object.create({}); (state as any).core.auth = authenticatedState; }); - authService = new AuthService({}, window, undefined, authReqService, router, cookieService, store, rdbService); + authService = new AuthService( {}, window, undefined, authReqService, router, cookieService, store, rdbService); })); it('should return true when user is logged in', () => { diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 90a91d81f3..ab1d38b79e 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -43,7 +43,7 @@ export class AuthService { protected _authenticated: boolean; constructor( - @Inject(GLOBAL_CONFIG) public config: GlobalConfig, + // @Inject(GLOBAL_CONFIG) public config: GlobalConfig, @Inject(REQUEST) protected req: any, @Inject(NativeWindowService) protected _window: NativeWindowRef, protected authRequestService: AuthRequestService, @@ -203,18 +203,20 @@ export class AuthService { */ public retrieveAuthMethods(): Observable { console.log('auth.service retrieveAuthMethods() was called'); - return this.authRequestService.getRequest('login').pipe( + // return this.authRequestService.getRequest('login').pipe( + return this.authRequestService.postToEndpoint('login', {}).pipe( map((status: AuthStatus) => { let url = ''; 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'; } return url; }) ) } - private parseSSOLocation(url: string): string { +/* private parseSSOLocation(url: string): string { console.log('auth.service parseSSOLocation was called'); const parseUrl = decodeURIComponent(url); // const urlTree: UrlTree = this.router.parseUrl(url); @@ -227,7 +229,7 @@ export class AuthService { // console.log(url); const target = `?target=${this.config.auth.target.host}${this.config.auth.target.page}`; return parseUrl.replace(/\?target=http.+/g, target); - } + }*/ /** * Create a new user