From 6167012e32c0feff438e37246012a99c9e700f78 Mon Sep 17 00:00:00 2001 From: Julius Gruber Date: Wed, 4 Sep 2019 16:19:59 +0200 Subject: [PATCH] Basic implmentation of the dynamic rendering of Authentication Methods --- src/app/core/auth/auth.effects.ts | 6 +++--- src/app/core/auth/auth.service.ts | 13 +++++++++++++ src/app/shared/log-in/authMethods-decorator.ts | 1 + .../log-in/container/login-container.component.ts | 13 ------------- .../shibboleth/dynamic-shibboleth.component.ts | 2 +- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/app/core/auth/auth.effects.ts b/src/app/core/auth/auth.effects.ts index 5126a30540..0bb173edfb 100644 --- a/src/app/core/auth/auth.effects.ts +++ b/src/app/core/auth/auth.effects.ts @@ -62,17 +62,17 @@ export class AuthEffects { * Authenticate user. * @method authenticate */ -/* @Effect() + @Effect() public shibbolethAuthenticate$: Observable = this.actions$.pipe( ofType(AuthActionTypes.START_SHIBBOLETH_AUTHENTICATION), switchMap((action: StartShibbolethAuthenticationAction) => { - return this.authService.authenticate(action.payload.location).pipe( + return this.authService.shibbolethAuthenticate(action.payload.location).pipe( take(1), map((response: AuthStatus) => new AuthenticationSuccessAction(response.token)), catchError((error) => observableOf(new AuthenticationErrorAction(error))) ); }) - );*/ + ); /** * Shib Login. diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 7df511b4b3..1dc32f25ac 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -115,6 +115,19 @@ export class AuthService { } + shibbolethAuthenticate(location: string) { + // implement a call to the backend here + console.log('location: ', location); + return this.authRequestService.postToEndpoint('login').pipe( + map((status: AuthStatus) => { + if (status.authenticated) { + return status; + } else { + throw(new Error('Shibboleth login failed')); + } + })) + } + public startShibbAuth(): Observable { console.log('startShibAuth() was called'); // Attempt authenticating the user after the shibboleth/saml response reached the backend diff --git a/src/app/shared/log-in/authMethods-decorator.ts b/src/app/shared/log-in/authMethods-decorator.ts index 6769443276..1786129bd1 100644 --- a/src/app/shared/log-in/authMethods-decorator.ts +++ b/src/app/shared/log-in/authMethods-decorator.ts @@ -1,6 +1,7 @@ import { AuthMethodType } from './authMethods-type'; const authMethodsMap = new Map(); + export function renderAuthMethodFor(authMethodType: AuthMethodType) { return function decorator(objectElement: any) { if (!objectElement) { diff --git a/src/app/shared/log-in/container/login-container.component.ts b/src/app/shared/log-in/container/login-container.component.ts index daa68bc8c3..a4e04bfb76 100644 --- a/src/app/shared/log-in/container/login-container.component.ts +++ b/src/app/shared/log-in/container/login-container.component.ts @@ -1,13 +1,8 @@ import { Component, ContentChild, Injector, Input, OnInit, ViewChild, ViewChildren } from '@angular/core'; import { rendersAuthMethodType } from '../authMethods-decorator'; import { AuthMethodModel } from '../../../core/auth/models/auth-method.model'; -import { getAuthenticationMethods, isAuthenticated, isAuthenticationLoading } from '../../../core/auth/selectors'; import { select, Store } from '@ngrx/store'; -import { AppState } from '../../../app.reducer'; -import { Observable } from 'rxjs'; -import { AuthMethodType } from '../authMethods-type'; import { CoreState } from '../../../core/core.reducers'; -import { ShibbolethComponent } from '../../../+login-page/shibbolethTargetPage/shibboleth.component'; /** * This component represents a section that contains the submission license form. @@ -45,9 +40,6 @@ export class LoginContainerComponent implements OnInit { ], parent: this.injector }); - - - } /** @@ -57,9 +49,4 @@ export class LoginContainerComponent implements OnInit { return rendersAuthMethodType(this.authMethodModel.authMethodType) } - startShibbolethAuthentication($event) { - console.log('startShibbolethAuthentication() was called with event: ', $event); - // this.store.dispatch(new ShibbolethAuthenticateAction()); - } - } diff --git a/src/app/shared/log-in/methods/shibboleth/dynamic-shibboleth.component.ts b/src/app/shared/log-in/methods/shibboleth/dynamic-shibboleth.component.ts index 7994ce3bf0..491bb8b1b2 100644 --- a/src/app/shared/log-in/methods/shibboleth/dynamic-shibboleth.component.ts +++ b/src/app/shared/log-in/methods/shibboleth/dynamic-shibboleth.component.ts @@ -49,7 +49,7 @@ export class DynamicShibbolethComponent implements OnInit { } ngOnInit(): void { - console.log('injectedAuthMethodModel', this.injectedAuthMethodModel); + // console.log('injectedAuthMethodModel', this.injectedAuthMethodModel); // set formGroup this.shibbForm = this.formBuilder.group({ shibbButton: [''],