diff --git a/src/app/core/auth/auth-request.service.ts b/src/app/core/auth/auth-request.service.ts index 7b2620bf13..276fb506c5 100644 --- a/src/app/core/auth/auth-request.service.ts +++ b/src/app/core/auth/auth-request.service.ts @@ -10,6 +10,7 @@ import {AuthGetRequest, AuthPostRequest, GetRequest, PostRequest, RestRequest} f import {AuthStatusResponse, ErrorResponse} from '../cache/response.models'; import {HttpOptions} from '../dspace-rest-v2/dspace-rest-v2.service'; import {getResponseFromEntry} from '../shared/operators'; +import {HttpClient} from '@angular/common/http'; @Injectable() export class AuthRequestService { @@ -18,7 +19,8 @@ export class AuthRequestService { constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, protected halService: HALEndpointService, - protected requestService: RequestService) { + protected requestService: RequestService, + private http: HttpClient) { } protected fetchRequest(request: RestRequest): Observable { @@ -51,6 +53,26 @@ export class AuthRequestService { distinctUntilChanged()); } + postToShibbEndpoint(): Observable { + console.log('postToShibbLogin() was called'); + return this.http.post('https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login', + { + name: 'morpheus', + job: 'leader' + }) + /* .subscribe( + (val) => { + console.log('POST call successful value returned in body', + val); + }, + (response) => { + console.log('POST call in error', response); + }, + () => { + console.log('The POST observable is now completed.'); + });*/ + } + public getRequest(method: string, options?: HttpOptions): Observable { console.log('auth.request getRequest() was called'); return this.halService.getEndpoint(this.linkName).pipe( @@ -64,4 +86,5 @@ export class AuthRequestService { mergeMap((request: GetRequest) => this.fetchRequest(request)), distinctUntilChanged()); } + } diff --git a/src/app/core/auth/auth.actions.ts b/src/app/core/auth/auth.actions.ts index c2ab855aad..cf6b16bb63 100644 --- a/src/app/core/auth/auth.actions.ts +++ b/src/app/core/auth/auth.actions.ts @@ -10,6 +10,7 @@ import { AuthTokenInfo } from './models/auth-token-info.model'; export const AuthActionTypes = { AUTHENTICATE: type('dspace/auth/AUTHENTICATE'), + SHIBB_LOGIN: type('dspace/auth/SHIBB_LOGIN'), AUTHENTICATE_ERROR: type('dspace/auth/AUTHENTICATE_ERROR'), AUTHENTICATE_SUCCESS: type('dspace/auth/AUTHENTICATE_SUCCESS'), AUTHENTICATED: type('dspace/auth/AUTHENTICATED'), @@ -55,6 +56,22 @@ export class AuthenticateAction implements Action { } } +/** + * ShibbLoginAction. + * @class ShibbLoginAction + * @implements {Action} + */ +export class ShibbLoginAction implements Action { + public type: string = AuthActionTypes.SHIBB_LOGIN; + payload: { + ssoLoginUrl: string; + }; + + constructor(ssoLoginUrl: string) { + this.payload = { ssoLoginUrl }; + } +} + /** * Checks if user is authenticated. * @class AuthenticatedAction @@ -366,6 +383,7 @@ export class SetRedirectUrlAction implements Action { */ export type AuthActions = AuthenticateAction + | ShibbLoginAction | AuthenticatedAction | AuthenticatedErrorAction | AuthenticatedSuccessAction diff --git a/src/app/core/auth/auth.effects.ts b/src/app/core/auth/auth.effects.ts index 6d277aaa1b..57745cf823 100644 --- a/src/app/core/auth/auth.effects.ts +++ b/src/app/core/auth/auth.effects.ts @@ -26,7 +26,11 @@ import { RefreshTokenSuccessAction, RegistrationAction, RegistrationErrorAction, - RegistrationSuccessAction, RetrieveAuthMethodsAction, RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsSuccessAction + RegistrationSuccessAction, + RetrieveAuthMethodsAction, + RetrieveAuthMethodsErrorAction, + RetrieveAuthMethodsSuccessAction, + ShibbLoginAction } from './auth.actions'; import { EPerson } from '../eperson/models/eperson.model'; import { AuthStatus } from './models/auth-status.model'; @@ -54,6 +58,22 @@ export class AuthEffects { }) ); + /** + * Shib Login. + * @method shibLogin + */ + @Effect() + public shibbLogin$: Observable = this.actions$.pipe( + ofType(AuthActionTypes.SHIBB_LOGIN), + switchMap((action: ShibbLoginAction) => { + return this.authService.startShibbAuth().pipe( + take(1), + map((response: AuthStatus) => new AuthenticationSuccessAction(response.token)), + catchError((error) => observableOf(new AuthenticationErrorAction(error))) + ); + }) + ); + @Effect() public authenticateSuccess$: Observable = this.actions$.pipe( ofType(AuthActionTypes.AUTHENTICATE_SUCCESS), diff --git a/src/app/core/auth/auth.reducer.ts b/src/app/core/auth/auth.reducer.ts index b22063ad77..e9281321f1 100644 --- a/src/app/core/auth/auth.reducer.ts +++ b/src/app/core/auth/auth.reducer.ts @@ -78,6 +78,13 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut info: undefined }); + case AuthActionTypes.SHIBB_LOGIN: + return Object.assign({}, state, { + error: undefined, + loading: true, + info: undefined + }); + case AuthActionTypes.AUTHENTICATED: return Object.assign({}, state, { loading: true diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index f0e53a3e07..a563408a96 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -114,6 +114,17 @@ export class AuthService { } + public startShibbAuth(): Observable { + return this.authRequestService.postToShibbEndpoint().pipe( + map((status: AuthStatus) => { + if (status.authenticated) { + return status; + } else { + throw(new Error('Invalid email or password')); + } + })) + } + /** * Determines if the user is authenticated * @returns {Observable} @@ -440,4 +451,5 @@ export class AuthService { this.store.dispatch(new SetRedirectUrlAction('')); this.storage.remove(REDIRECT_COOKIE); } + } diff --git a/src/app/shared/log-in/log-in.component.html b/src/app/shared/log-in/log-in.component.html index 8c6f28649c..806a8b92bc 100644 --- a/src/app/shared/log-in/log-in.component.html +++ b/src/app/shared/log-in/log-in.component.html @@ -34,6 +34,12 @@ + + +

Simple Post Login diff --git a/src/app/shared/log-in/log-in.component.ts b/src/app/shared/log-in/log-in.component.ts index 8e8c90985e..ce5f6d7cdb 100644 --- a/src/app/shared/log-in/log-in.component.ts +++ b/src/app/shared/log-in/log-in.component.ts @@ -6,7 +6,7 @@ import {select, Store} from '@ngrx/store'; import {Observable} from 'rxjs'; import { AuthenticateAction, - ResetAuthenticationMessagesAction + ResetAuthenticationMessagesAction, ShibbLoginAction } from '../../core/auth/auth.actions'; import { @@ -232,4 +232,24 @@ export class LogInComponent implements OnDestroy, OnInit { }); } + dispatchShibbLoginAction() { + const ssoLoginUrl = 'https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login' + // this.store.dispatch(new ShibbLoginAction(ssoLoginUrl)); + this.http.post(ssoLoginUrl, + { + name: 'morpheus', + job: 'leader' + }) + .subscribe( + (val) => { + console.log('POST call successful value returned in body', + val); + }, + (response) => { + console.log('POST call in error', response); + }, + () => { + console.log('The POST observable is now completed.'); + }); + } }