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 {AuthStatusResponse, ErrorResponse} from '../cache/response.models';
|
||||||
import {HttpOptions} from '../dspace-rest-v2/dspace-rest-v2.service';
|
import {HttpOptions} from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||||
import {getResponseFromEntry} from '../shared/operators';
|
import {getResponseFromEntry} from '../shared/operators';
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthRequestService {
|
export class AuthRequestService {
|
||||||
@@ -18,7 +19,8 @@ export class AuthRequestService {
|
|||||||
|
|
||||||
constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
||||||
protected halService: HALEndpointService,
|
protected halService: HALEndpointService,
|
||||||
protected requestService: RequestService) {
|
protected requestService: RequestService,
|
||||||
|
private http: HttpClient) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fetchRequest(request: RestRequest): Observable<any> {
|
protected fetchRequest(request: RestRequest): Observable<any> {
|
||||||
@@ -51,6 +53,26 @@ 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(
|
||||||
@@ -64,4 +86,5 @@ export class AuthRequestService {
|
|||||||
mergeMap((request: GetRequest) => this.fetchRequest(request)),
|
mergeMap((request: GetRequest) => this.fetchRequest(request)),
|
||||||
distinctUntilChanged());
|
distinctUntilChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ import { AuthTokenInfo } from './models/auth-token-info.model';
|
|||||||
|
|
||||||
export const AuthActionTypes = {
|
export const AuthActionTypes = {
|
||||||
AUTHENTICATE: type('dspace/auth/AUTHENTICATE'),
|
AUTHENTICATE: type('dspace/auth/AUTHENTICATE'),
|
||||||
|
SHIBB_LOGIN: type('dspace/auth/SHIBB_LOGIN'),
|
||||||
AUTHENTICATE_ERROR: type('dspace/auth/AUTHENTICATE_ERROR'),
|
AUTHENTICATE_ERROR: type('dspace/auth/AUTHENTICATE_ERROR'),
|
||||||
AUTHENTICATE_SUCCESS: type('dspace/auth/AUTHENTICATE_SUCCESS'),
|
AUTHENTICATE_SUCCESS: type('dspace/auth/AUTHENTICATE_SUCCESS'),
|
||||||
AUTHENTICATED: type('dspace/auth/AUTHENTICATED'),
|
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.
|
* Checks if user is authenticated.
|
||||||
* @class AuthenticatedAction
|
* @class AuthenticatedAction
|
||||||
@@ -366,6 +383,7 @@ export class SetRedirectUrlAction implements Action {
|
|||||||
*/
|
*/
|
||||||
export type AuthActions
|
export type AuthActions
|
||||||
= AuthenticateAction
|
= AuthenticateAction
|
||||||
|
| ShibbLoginAction
|
||||||
| AuthenticatedAction
|
| AuthenticatedAction
|
||||||
| AuthenticatedErrorAction
|
| AuthenticatedErrorAction
|
||||||
| AuthenticatedSuccessAction
|
| AuthenticatedSuccessAction
|
||||||
|
@@ -26,7 +26,11 @@ import {
|
|||||||
RefreshTokenSuccessAction,
|
RefreshTokenSuccessAction,
|
||||||
RegistrationAction,
|
RegistrationAction,
|
||||||
RegistrationErrorAction,
|
RegistrationErrorAction,
|
||||||
RegistrationSuccessAction, RetrieveAuthMethodsAction, RetrieveAuthMethodsErrorAction, RetrieveAuthMethodsSuccessAction
|
RegistrationSuccessAction,
|
||||||
|
RetrieveAuthMethodsAction,
|
||||||
|
RetrieveAuthMethodsErrorAction,
|
||||||
|
RetrieveAuthMethodsSuccessAction,
|
||||||
|
ShibbLoginAction
|
||||||
} from './auth.actions';
|
} from './auth.actions';
|
||||||
import { EPerson } from '../eperson/models/eperson.model';
|
import { EPerson } from '../eperson/models/eperson.model';
|
||||||
import { AuthStatus } from './models/auth-status.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()
|
@Effect()
|
||||||
public authenticateSuccess$: Observable<Action> = this.actions$.pipe(
|
public authenticateSuccess$: Observable<Action> = this.actions$.pipe(
|
||||||
ofType(AuthActionTypes.AUTHENTICATE_SUCCESS),
|
ofType(AuthActionTypes.AUTHENTICATE_SUCCESS),
|
||||||
|
@@ -78,6 +78,13 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut
|
|||||||
info: undefined
|
info: undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
|
case AuthActionTypes.SHIBB_LOGIN:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
error: undefined,
|
||||||
|
loading: true,
|
||||||
|
info: undefined
|
||||||
|
});
|
||||||
|
|
||||||
case AuthActionTypes.AUTHENTICATED:
|
case AuthActionTypes.AUTHENTICATED:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
loading: true
|
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
|
* Determines if the user is authenticated
|
||||||
* @returns {Observable<boolean>}
|
* @returns {Observable<boolean>}
|
||||||
@@ -440,4 +451,5 @@ export class AuthService {
|
|||||||
this.store.dispatch(new SetRedirectUrlAction(''));
|
this.store.dispatch(new SetRedirectUrlAction(''));
|
||||||
this.storage.remove(REDIRECT_COOKIE);
|
this.storage.remove(REDIRECT_COOKIE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div >
|
||||||
|
<br>
|
||||||
|
<a class="btn btn-lg btn-primary btn-block mt-2" (click)="dispatchShibbLoginAction()" role="button">Dispatch Shibb Login</a>
|
||||||
|
</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>
|
||||||
|
@@ -6,7 +6,7 @@ import {select, Store} from '@ngrx/store';
|
|||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {
|
import {
|
||||||
AuthenticateAction,
|
AuthenticateAction,
|
||||||
ResetAuthenticationMessagesAction
|
ResetAuthenticationMessagesAction, ShibbLoginAction
|
||||||
} from '../../core/auth/auth.actions';
|
} from '../../core/auth/auth.actions';
|
||||||
|
|
||||||
import {
|
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