mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Test CORS policy'
This commit is contained in:
@@ -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<any> {
|
||||
@@ -51,6 +53,26 @@ export class AuthRequestService {
|
||||
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> {
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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<Action> = 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<Action> = this.actions$.pipe(
|
||||
ofType(AuthActionTypes.AUTHENTICATE_SUCCESS),
|
||||
|
@@ -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
|
||||
|
@@ -114,6 +114,17 @@ export class AuthService {
|
||||
|
||||
}
|
||||
|
||||
public startShibbAuth(): Observable<AuthStatus> {
|
||||
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<boolean>}
|
||||
@@ -440,4 +451,5 @@ export class AuthService {
|
||||
this.store.dispatch(new SetRedirectUrlAction(''));
|
||||
this.storage.remove(REDIRECT_COOKIE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,6 +34,12 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div >
|
||||
<br>
|
||||
<a class="btn btn-lg btn-primary btn-block mt-2" (click)="dispatchShibbLoginAction()" role="button">Dispatch Shibb Login</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div >
|
||||
<br>
|
||||
<a class="btn btn-lg btn-primary btn-block mt-2" (click)="postLoginCall()" role="button">Simple Post Login</a>
|
||||
|
@@ -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.');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user