Commit 39099947 authored by François Agneray's avatar François Agneray

Chekc auth server + login redirect url

parent 01661a94
Pipeline #3470 passed with stages
in 8 minutes and 37 seconds
......@@ -14,7 +14,6 @@ export const CHECK_AUTH_COMPLETE = '[Auth] Check Auth Complete';
export const LOGIN = '[Auth] Login';
export const LOGIN_COMPLETE = '[Auth] Login Complete';
export const LOGOUT = '[Auth] Logout';
export const LOGOUT_COMPLETE = '[Auth] Logout Complete';
export const OPEN_EDIT_PROFILE = '[Auth] Edit Profile';
export class CheckAuthAction implements Action {
......@@ -37,7 +36,7 @@ export class CheckAuthCompleteAction implements Action {
export class LoginAction implements Action {
readonly type = LOGIN;
constructor(public payload: {} = null) { }
constructor(public payload: string = null) { }
}
export class LoginCompleteAction implements Action {
......@@ -58,12 +57,6 @@ export class LogoutAction implements Action {
constructor(public payload: {} = null) { }
}
export class LogoutCompleteAction implements Action {
readonly type = LOGOUT_COMPLETE;
constructor(public payload: {} = null) { }
}
export class OpenEditProfileAction implements Action {
readonly type = OPEN_EDIT_PROFILE;
......@@ -76,5 +69,4 @@ export type Actions
| LoginAction
| LoginCompleteAction
| LogoutAction
| LogoutCompleteAction
| OpenEditProfileAction;
......@@ -36,7 +36,13 @@ export class AuthEffects {
@Effect({ dispatch: false })
loginAction$ = this.actions$.pipe(
ofType(authActions.LOGIN),
tap(_ => this.authService.doLogin())
tap((action: authActions.LoginAction) => {
const redirectUrl = action.payload;
if (redirectUrl !== null) {
sessionStorage.setItem(environment.ssoClientId + '_redirectUrl', this.router.url);
}
return this.authService.doLogin()
})
);
@Effect()
......@@ -64,22 +70,27 @@ export class AuthEffects {
)
);
} else {
return of(new authActions.LogoutCompleteAction())
return of({ type: '[No Action] ' + authActions.CHECK_AUTH_COMPLETE });
}
})
);
@Effect()
logoutAction$ = this.actions$.pipe(
ofType(authActions.LOGOUT),
tap(_ => this.authService.signOut()),
map(() => new authActions.LogoutCompleteAction())
@Effect({ dispatch: false })
loginCompleteAction$ = this.actions$.pipe(
ofType(authActions.LOGIN_COMPLETE),
tap(_ => {
const redirectUrl = sessionStorage.getItem(environment.ssoClientId + '_redirectUrl');
if (redirectUrl !== null) {
sessionStorage.removeItem(environment.ssoClientId + '_redirectUrl');
this.router.navigateByUrl(redirectUrl);
}
})
);
@Effect({ dispatch: false })
logoutCompleteAction$ = this.actions$.pipe(
ofType(authActions.LOGOUT_COMPLETE),
tap(_ => this.router.navigate(['/']))
logoutAction$ = this.actions$.pipe(
ofType(authActions.LOGOUT),
tap(_ => this.authService.signOut())
);
/**
......
......@@ -20,7 +20,7 @@ export class AuthService {
}
checkAuth() {
return this.oidcSecurityService.checkAuth();
return this.oidcSecurityService.checkAuthIncludingServer();
}
doLogin() {
......
......@@ -6,14 +6,14 @@ export function configureAuth(oidcConfigService: OidcConfigService) {
return () =>
oidcConfigService.withConfig({
stsServer: environment.ssoAuthUrl,
redirectUrl: window.location.origin + environment.ssoRedirectUrl,
postLogoutRedirectUri: window.location.origin + environment.ssoLogoutRedirectUri,
redirectUrl: window.location.origin,
postLogoutRedirectUri: window.location.origin,
clientId: environment.ssoClientId,
scope: 'openid profile email offline_access',
responseType: 'code',
silentRenew: true,
silentRenewUrl: `${window.location.origin}/silent-renew.html`,
renewTimeBeforeTokenExpiresInSeconds: 10,
logLevel: LogLevel.Debug,
logLevel: LogLevel.None,
});
}
......@@ -55,7 +55,7 @@ describe('[Core] Container: AppComponent', () => {
});
it('#login() should dispatch LoginAction', () => {
const loginAction = new authActions.LoginAction();
const loginAction = new authActions.LoginAction('/');
const spy = spyOn(store, 'dispatch');
component.login();
expect(spy).toHaveBeenCalledTimes(1);
......
......@@ -8,6 +8,7 @@
*/
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
......@@ -50,7 +51,7 @@ export class AppComponent implements OnInit {
public userProfile: Observable<any>;
public instance: Observable<Instance>;
constructor(private store: Store<StoreState>) {
constructor(private store: Store<StoreState>, private router: Router) {
this.isAuthenticated = store.select(authSelector.isAuthenticated);
this.userProfile = store.select(authSelector.getUserProfile);
this.instance = store.select(metamodelSelector.getInstance);
......@@ -65,7 +66,7 @@ export class AppComponent implements OnInit {
* Dispatches action to log in.
*/
login(): void {
this.store.dispatch(new authActions.LoginAction());
this.store.dispatch(new authActions.LoginAction(this.router.url));
}
/**
......
......@@ -15,7 +15,5 @@ export const environment = {
instanceName: 'default',
baseHref: '/',
ssoAuthUrl: 'https://anis-dev.lam.fr/auth/realms/anis',
ssoClientId: 'anis-client',
ssoRedirectUrl: '',
ssoLogoutRedirectUri: ''
ssoClientId: 'anis-client'
};
......@@ -19,7 +19,5 @@ export const environment = {
instanceName: 'default',
baseHref: '/',
ssoAuthUrl: 'http://localhost:8180/auth/realms/anis',
ssoClientId: 'anis-client',
ssoRedirectUrl: '',
ssoLogoutRedirectUri: ''
ssoClientId: 'anis-client'
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment