From 0355ff3e47a95b2dc9fd9f108e31deb8f5bce434 Mon Sep 17 00:00:00 2001 From: Julius Gruber Date: Tue, 18 Jun 2019 15:07:36 +0200 Subject: [PATCH] Get tokoen from backend --- src/app/core/auth/auth-request.service.ts | 22 +---------- src/app/core/auth/auth.actions.ts | 41 ++++++++++----------- src/app/core/auth/auth.service.ts | 3 +- src/app/shared/log-in/log-in.component.html | 39 ++++++++++++-------- src/app/shared/log-in/log-in.component.ts | 31 +++++----------- 5 files changed, 54 insertions(+), 82 deletions(-) diff --git a/src/app/core/auth/auth-request.service.ts b/src/app/core/auth/auth-request.service.ts index 276fb506c5..23c767c61b 100644 --- a/src/app/core/auth/auth-request.service.ts +++ b/src/app/core/auth/auth-request.service.ts @@ -40,7 +40,7 @@ export class AuthRequestService { return isNotEmpty(method) ? `${endpoint}/${method}` : `${endpoint}`; } - public postToEndpoint(method: string, body: any, options?: HttpOptions): Observable { + public postToEndpoint(method: string, body?: any, options?: HttpOptions): Observable { return this.halService.getEndpoint(this.linkName).pipe( filter((href: string) => isNotEmpty(href)), tap((href: string) => console.log('This is href in postToEndpoint(): ' , href)), @@ -53,26 +53,6 @@ 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( diff --git a/src/app/core/auth/auth.actions.ts b/src/app/core/auth/auth.actions.ts index cf6b16bb63..f949536aac 100644 --- a/src/app/core/auth/auth.actions.ts +++ b/src/app/core/auth/auth.actions.ts @@ -1,12 +1,12 @@ // import @ngrx -import { Action } from '@ngrx/store'; +import {Action} from '@ngrx/store'; // import type function -import { type } from '../../shared/ngrx/type'; +import {type} from '../../shared/ngrx/type'; // import models -import { EPerson } from '../eperson/models/eperson.model'; -import { AuthTokenInfo } from './models/auth-token-info.model'; +import {EPerson} from '../eperson/models/eperson.model'; +import {AuthTokenInfo} from './models/auth-token-info.model'; export const AuthActionTypes = { AUTHENTICATE: type('dspace/auth/AUTHENTICATE'), @@ -52,7 +52,7 @@ export class AuthenticateAction implements Action { }; constructor(email: string, password: string) { - this.payload = { email, password }; + this.payload = {email, password}; } } @@ -63,13 +63,6 @@ export class AuthenticateAction implements Action { */ export class ShibbLoginAction implements Action { public type: string = AuthActionTypes.SHIBB_LOGIN; - payload: { - ssoLoginUrl: string; - }; - - constructor(ssoLoginUrl: string) { - this.payload = { ssoLoginUrl }; - } } /** @@ -100,7 +93,7 @@ export class AuthenticatedSuccessAction implements Action { }; constructor(authenticated: boolean, authToken: AuthTokenInfo, user: EPerson) { - this.payload = { authenticated, authToken, user }; + this.payload = {authenticated, authToken, user}; } } @@ -114,7 +107,7 @@ export class AuthenticatedErrorAction implements Action { payload: Error; constructor(payload: Error) { - this.payload = payload ; + this.payload = payload; } } @@ -128,7 +121,7 @@ export class AuthenticationErrorAction implements Action { payload: Error; constructor(payload: Error) { - this.payload = payload ; + this.payload = payload; } } @@ -171,7 +164,9 @@ export class CheckAuthenticationTokenErrorAction implements Action { */ export class LogOutAction implements Action { public type: string = AuthActionTypes.LOG_OUT; - constructor(public payload?: any) {} + + constructor(public payload?: any) { + } } /** @@ -184,7 +179,7 @@ export class LogOutErrorAction implements Action { payload: Error; constructor(payload: Error) { - this.payload = payload ; + this.payload = payload; } } @@ -195,7 +190,9 @@ export class LogOutErrorAction implements Action { */ export class LogOutSuccessAction implements Action { public type: string = AuthActionTypes.LOG_OUT_SUCCESS; - constructor(public payload?: any) {} + + constructor(public payload?: any) { + } } /** @@ -208,7 +205,7 @@ export class RedirectWhenAuthenticationIsRequiredAction implements Action { payload: string; constructor(message: string) { - this.payload = message ; + this.payload = message; } } @@ -222,7 +219,7 @@ export class RedirectWhenTokenExpiredAction implements Action { payload: string; constructor(message: string) { - this.payload = message ; + this.payload = message; } } @@ -287,7 +284,7 @@ export class RegistrationErrorAction implements Action { payload: Error; constructor(payload: Error) { - this.payload = payload ; + this.payload = payload; } } @@ -371,7 +368,7 @@ export class SetRedirectUrlAction implements Action { payload: string; constructor(url: string) { - this.payload = url ; + this.payload = url; } } diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index a563408a96..d10e878595 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -115,7 +115,8 @@ export class AuthService { } public startShibbAuth(): Observable { - return this.authRequestService.postToShibbEndpoint().pipe( + console.log('startShibAuth() was called'); + return this.authRequestService.postToEndpoint('login').pipe( map((status: AuthStatus) => { if (status.authenticated) { return status; diff --git a/src/app/shared/log-in/log-in.component.html b/src/app/shared/log-in/log-in.component.html index 806a8b92bc..85809d77d6 100644 --- a/src/app/shared/log-in/log-in.component.html +++ b/src/app/shared/log-in/log-in.component.html @@ -1,5 +1,6 @@ -