diff --git a/src/app/core/auth/auth.actions.ts b/src/app/core/auth/auth.actions.ts index 5671b1d4ca..cf7f325653 100644 --- a/src/app/core/auth/auth.actions.ts +++ b/src/app/core/auth/auth.actions.ts @@ -11,6 +11,7 @@ import { AuthMethodModel } from './models/auth-method.model'; export const AuthActionTypes = { AUTHENTICATE: type('dspace/auth/AUTHENTICATE'), + START_SHIBBOLETH_AUTHENTICATION: type('dspace/auth/START_SHIBBOLETH_AUTHENTICATION'), GET_JWT_AFTER_SHIBB_LOGIN: type('dspace/auth/GET_JWT_AFTER_SHIBB_LOGIN'), AUTHENTICATE_ERROR: type('dspace/auth/AUTHENTICATE_ERROR'), AUTHENTICATE_SUCCESS: type('dspace/auth/AUTHENTICATE_SUCCESS'), @@ -57,6 +58,20 @@ export class AuthenticateAction implements Action { } } +/** + * Authenticate. + * @class StartShibbolethAuthenticationAction + * @implements {Action} + */ +export class StartShibbolethAuthenticationAction implements Action { + public type: string = AuthActionTypes.START_SHIBBOLETH_AUTHENTICATION; + payload: AuthMethodModel; + + constructor(authMethodModel: AuthMethodModel) { + this.payload = authMethodModel; + } +} + /** * GetJWTafterShibbLoginAction. * @class GetJWTafterShibbLoginAction diff --git a/src/app/core/auth/auth.effects.ts b/src/app/core/auth/auth.effects.ts index eb7bdaf42c..5126a30540 100644 --- a/src/app/core/auth/auth.effects.ts +++ b/src/app/core/auth/auth.effects.ts @@ -30,7 +30,7 @@ import { RetrieveAuthMethodsAction, RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsSuccessAction, - GetJWTafterShibbLoginAction + GetJWTafterShibbLoginAction, StartShibbolethAuthenticationAction } from './auth.actions'; import { EPerson } from '../eperson/models/eperson.model'; import { AuthStatus } from './models/auth-status.model'; @@ -48,15 +48,31 @@ export class AuthEffects { */ @Effect() public authenticate$: Observable = this.actions$.pipe( - ofType(AuthActionTypes.AUTHENTICATE), - switchMap((action: AuthenticateAction) => { - return this.authService.authenticate(action.payload.email, action.payload.password).pipe( - take(1), - map((response: AuthStatus) => new AuthenticationSuccessAction(response.token)), - catchError((error) => observableOf(new AuthenticationErrorAction(error))) - ); - }) - ); + ofType(AuthActionTypes.AUTHENTICATE), + switchMap((action: AuthenticateAction) => { + return this.authService.authenticate(action.payload.email, action.payload.password).pipe( + take(1), + map((response: AuthStatus) => new AuthenticationSuccessAction(response.token)), + catchError((error) => observableOf(new AuthenticationErrorAction(error))) + ); + }) + ); + + /** + * Authenticate user. + * @method authenticate + */ +/* @Effect() + public shibbolethAuthenticate$: Observable = this.actions$.pipe( + ofType(AuthActionTypes.START_SHIBBOLETH_AUTHENTICATION), + switchMap((action: StartShibbolethAuthenticationAction) => { + return this.authService.authenticate(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.reducer.ts b/src/app/core/auth/auth.reducer.ts index 3ff33d9f91..a23c8cceea 100644 --- a/src/app/core/auth/auth.reducer.ts +++ b/src/app/core/auth/auth.reducer.ts @@ -80,6 +80,13 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut info: undefined }); + case AuthActionTypes.START_SHIBBOLETH_AUTHENTICATION: + return Object.assign({}, state, { + error: undefined, + loading: true, + info: undefined + }); + case AuthActionTypes.GET_JWT_AFTER_SHIBB_LOGIN: return Object.assign({}, state, { error: undefined, diff --git a/src/app/shared/log-in/authMethods.component.html b/src/app/shared/log-in/authMethods.component.html index d562d92f9d..1af185c707 100644 --- a/src/app/shared/log-in/authMethods.component.html +++ b/src/app/shared/log-in/authMethods.component.html @@ -1,3 +1,4 @@ + diff --git a/src/app/shared/log-in/authMethods.component.ts b/src/app/shared/log-in/authMethods.component.ts index 65e68bb8b2..5a42cb73a7 100644 --- a/src/app/shared/log-in/authMethods.component.ts +++ b/src/app/shared/log-in/authMethods.component.ts @@ -1,9 +1,9 @@ import { Component, Injector, Input, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { AuthMethodModel } from '../../core/auth/models/auth-method.model'; -import { Store } from '@ngrx/store'; -import { AuthState } from '../../core/auth/auth.reducer'; -import { getAuthenticationMethods } from '../../core/auth/selectors'; +import { select, Store } from '@ngrx/store'; +import { getAuthenticationMethods, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors'; +import { CoreState } from '../../core/core.reducers'; @Component({ selector: 'ds-auth-methods', @@ -17,11 +17,29 @@ export class AuthMethodsComponent implements OnInit { */ @Input() authMethodData: Observable; - constructor( private store: Store) { + /** + * Whether user is authenticated. + * @type {Observable} + */ + public isAuthenticated: Observable; + + /** + * True if the authentication is loading. + * @type {boolean} + */ + public loading: Observable; + + constructor( private store: Store) { } ngOnInit(): void { this.authMethodData = this.authMethodData = this.store.select(getAuthenticationMethods); + + // set loading + this.loading = this.store.pipe(select(isAuthenticationLoading)); + + // set isAuthenticated + this.isAuthenticated = this.store.pipe(select(isAuthenticated)); } } diff --git a/src/app/shared/log-in/container/login-container.component.html b/src/app/shared/log-in/container/login-container.component.html index 937374b96d..cc73919710 100644 --- a/src/app/shared/log-in/container/login-container.component.html +++ b/src/app/shared/log-in/container/login-container.component.html @@ -1,2 +1,3 @@ - + + 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 2357552895..daa68bc8c3 100644 --- a/src/app/shared/log-in/container/login-container.component.ts +++ b/src/app/shared/log-in/container/login-container.component.ts @@ -1,11 +1,13 @@ -import { Component, Injector, Input, OnInit, ViewChild } from '@angular/core'; +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 } from '../../../core/auth/selectors'; -import { Store } from '@ngrx/store'; +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. @@ -30,7 +32,7 @@ export class LoginContainerComponent implements OnInit { * * @param {Injector} injector */ - constructor(private injector: Injector) { + constructor(private injector: Injector, private store: Store) { } /** @@ -44,12 +46,20 @@ export class LoginContainerComponent implements OnInit { parent: this.injector }); - } + + + } /** - * Find the correct component based on the authMethod's type + * Find the correct component based on the AuthMethod's type */ getAuthMethodContent(): string { 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/password/log-in-password.component.html b/src/app/shared/log-in/methods/password/log-in-password.component.html index 3ae3500f01..0a1c9dcc34 100644 --- a/src/app/shared/log-in/methods/password/log-in-password.component.html +++ b/src/app/shared/log-in/methods/password/log-in-password.component.html @@ -1,4 +1,3 @@ -