Get tokoen from backend

This commit is contained in:
Julius Gruber
2019-06-18 15:07:36 +02:00
parent 4504fa1818
commit 0355ff3e47
5 changed files with 54 additions and 82 deletions

View File

@@ -40,7 +40,7 @@ export class AuthRequestService {
return isNotEmpty(method) ? `${endpoint}/${method}` : `${endpoint}`; return isNotEmpty(method) ? `${endpoint}/${method}` : `${endpoint}`;
} }
public postToEndpoint(method: string, body: any, options?: HttpOptions): Observable<any> { public postToEndpoint(method: string, body?: any, options?: HttpOptions): Observable<any> {
return this.halService.getEndpoint(this.linkName).pipe( return this.halService.getEndpoint(this.linkName).pipe(
filter((href: string) => isNotEmpty(href)), filter((href: string) => isNotEmpty(href)),
tap((href: string) => console.log('This is href in postToEndpoint(): ' , href)), tap((href: string) => console.log('This is href in postToEndpoint(): ' , href)),
@@ -53,26 +53,6 @@ export class AuthRequestService {
distinctUntilChanged()); distinctUntilChanged());
} }
postToShibbEndpoint(): Observable<any> {
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<any> { public getRequest(method: string, options?: HttpOptions): Observable<any> {
console.log('auth.request getRequest() was called'); console.log('auth.request getRequest() was called');
return this.halService.getEndpoint(this.linkName).pipe( return this.halService.getEndpoint(this.linkName).pipe(

View File

@@ -1,12 +1,12 @@
// import @ngrx // import @ngrx
import { Action } from '@ngrx/store'; import {Action} from '@ngrx/store';
// import type function // import type function
import { type } from '../../shared/ngrx/type'; import {type} from '../../shared/ngrx/type';
// import models // import models
import { EPerson } from '../eperson/models/eperson.model'; import {EPerson} from '../eperson/models/eperson.model';
import { AuthTokenInfo } from './models/auth-token-info.model'; import {AuthTokenInfo} from './models/auth-token-info.model';
export const AuthActionTypes = { export const AuthActionTypes = {
AUTHENTICATE: type('dspace/auth/AUTHENTICATE'), AUTHENTICATE: type('dspace/auth/AUTHENTICATE'),
@@ -52,7 +52,7 @@ export class AuthenticateAction implements Action {
}; };
constructor(email: string, password: string) { 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 { export class ShibbLoginAction implements Action {
public type: string = AuthActionTypes.SHIBB_LOGIN; 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) { 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; payload: Error;
constructor(payload: Error) { constructor(payload: Error) {
this.payload = payload ; this.payload = payload;
} }
} }
@@ -128,7 +121,7 @@ export class AuthenticationErrorAction implements Action {
payload: Error; payload: Error;
constructor(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 { export class LogOutAction implements Action {
public type: string = AuthActionTypes.LOG_OUT; 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; payload: Error;
constructor(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 { export class LogOutSuccessAction implements Action {
public type: string = AuthActionTypes.LOG_OUT_SUCCESS; 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; payload: string;
constructor(message: string) { constructor(message: string) {
this.payload = message ; this.payload = message;
} }
} }
@@ -222,7 +219,7 @@ export class RedirectWhenTokenExpiredAction implements Action {
payload: string; payload: string;
constructor(message: string) { constructor(message: string) {
this.payload = message ; this.payload = message;
} }
} }
@@ -287,7 +284,7 @@ export class RegistrationErrorAction implements Action {
payload: Error; payload: Error;
constructor(payload: Error) { constructor(payload: Error) {
this.payload = payload ; this.payload = payload;
} }
} }
@@ -371,7 +368,7 @@ export class SetRedirectUrlAction implements Action {
payload: string; payload: string;
constructor(url: string) { constructor(url: string) {
this.payload = url ; this.payload = url;
} }
} }

View File

@@ -115,7 +115,8 @@ export class AuthService {
} }
public startShibbAuth(): Observable<AuthStatus> { public startShibbAuth(): Observable<AuthStatus> {
return this.authRequestService.postToShibbEndpoint().pipe( console.log('startShibAuth() was called');
return this.authRequestService.postToEndpoint('login').pipe(
map((status: AuthStatus) => { map((status: AuthStatus) => {
if (status.authenticated) { if (status.authenticated) {
return status; return status;

View File

@@ -1,5 +1,6 @@
<ds-loading *ngIf="(loading | async) || (isAuthenticated | async)" class="m-5"></ds-loading> <ds-loading *ngIf="(loading | async) || (isAuthenticated | async)" class="m-5"></ds-loading>
<form *ngIf="!(loading | async) && !(isAuthenticated | async)" class="form-login px-4 py-3" (ngSubmit)="submit()" [formGroup]="form" novalidate> <form *ngIf="!(loading | async) && !(isAuthenticated | async)" class="form-login px-4 py-3" (ngSubmit)="submit()"
[formGroup]="form" novalidate>
<label for="inputEmail" class="sr-only">{{"login.form.email" | translate}}</label> <label for="inputEmail" class="sr-only">{{"login.form.email" | translate}}</label>
<input id="inputEmail" <input id="inputEmail"
autocomplete="off" autocomplete="off"
@@ -17,34 +18,40 @@
formControlName="password" formControlName="password"
required required
type="password"> type="password">
<div *ngIf="(error | async) && hasError" class="alert alert-danger" role="alert" @fadeOut>{{ (error | async) | translate }}</div> <div *ngIf="(error | async) && hasError" class="alert alert-danger" role="alert"
<div *ngIf="(message | async) && hasMessage" class="alert alert-info" role="alert" @fadeOut>{{ (message | async) | translate }}</div> @fadeOut>{{ (error | async) | translate }}</div>
<div *ngIf="(message | async) && hasMessage" class="alert alert-info" role="alert"
@fadeOut>{{ (message | async) | translate }}</div>
<button class="btn btn-lg btn-primary btn-block mt-3" type="submit" [disabled]="!form.valid">{{"login.form.submit" | translate}}</button> <button class="btn btn-lg btn-primary btn-block mt-3" type="submit"
[disabled]="!form.valid">{{"login.form.submit" | translate}}</button>
<div *ngIf="(hasSsoLoginUrl | async)"> <div *ngIf="(hasSsoLoginUrl | async)">
<div class="text-center mt-2"><span class="align-middle">{{"login.form.or-divider" | translate}}</span></div> <div class="text-center mt-2"><span class="align-middle">{{"login.form.or-divider" | translate}}</span></div>
<a class="btn btn-lg btn-primary btn-block mt-2" [href]="(ssoLoginUrl | async)" role="button">{{"login.form.ssoLogin" | translate}}</a> <a class="btn btn-lg btn-primary btn-block mt-2" [href]="(ssoLoginUrl | async)"
role="button">{{"login.form.ssoLogin" | translate}}</a>
</div> </div>
<div > <div>
<br> <br>
<a class="btn btn-lg btn-primary btn-block mt-2" href="https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login" role="button">HardCoded Shibb</a> <a class="btn btn-lg btn-primary btn-block mt-2"
href="https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login"
role="button"
(click)="dispatchShibbLoginAction()">HardCoded Shibb</a>
</div> </div>
<div > <!-- <div >
<br> <br>
<a class="btn btn-lg btn-primary btn-block mt-2" (click)="dispatchShibbLoginAction()" role="button">Dispatch Shibb Login</a> <a class="btn btn-lg btn-primary btn-block mt-2" (click)="dispatchShibbLoginAction()" role="button">Dispatch Shibb Login</a>
</div> </div>
<div > <div >
<br> <br>
<a class="btn btn-lg btn-primary btn-block mt-2" (click)="postLoginCall()" role="button">Simple Post Login</a> <a class="btn btn-lg btn-primary btn-block mt-2" (click)="postLoginCall()" role="button">Simple Post Login</a>
</div> </div>-->
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>

View File

@@ -209,11 +209,11 @@ export class LogInComponent implements OnDestroy, OnInit {
this.form.reset(); this.form.reset();
} }
public postLoginCall() { /* public postLoginCall() {
console.log('postLoginCall() was called'); console.log('postLoginCall() was called');
/* const email = 'test@test.at'; /!* const email = 'test@test.at';
const password = 'test'; const password = 'test';
this.store.dispatch(new AuthenticateAction(email, password));*/ this.store.dispatch(new AuthenticateAction(email, password));*!/
this.http.post('https://fis.tiss.tuwien.ac.at/spring-rest/api/authn/login', this.http.post('https://fis.tiss.tuwien.ac.at/spring-rest/api/authn/login',
{ {
name: 'morpheus', name: 'morpheus',
@@ -230,26 +230,13 @@ export class LogInComponent implements OnDestroy, OnInit {
() => { () => {
console.log('The POST observable is now completed.'); console.log('The POST observable is now completed.');
}); });
} }*/
dispatchShibbLoginAction() { dispatchShibbLoginAction() {
const ssoLoginUrl = 'https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login' console.log('dispatchShibbLoginAction() was called');
// this.store.dispatch(new ShibbLoginAction(ssoLoginUrl)); // const ssoLoginUrl = 'https://fis.tiss.tuwien.ac.at/Shibboleth.sso/Login'
this.http.post(ssoLoginUrl, this.store.dispatch(new ShibbLoginAction());
{ // this.store.dispatch(new AuthenticateAction(email, password));
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.');
});
} }
} }