Refactor authentication flow
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma 2020-05-09 09:14:16 +02:00
parent 62887e8089
commit baf8767a91
5 changed files with 25 additions and 26 deletions

View File

@ -12,8 +12,7 @@ import {NotFoundComponent} from './components/not-found/not-found.component';
const routes = [ const routes = [
{ {
path: 'cb', path: 'cb',
component: AuthCallbackComponent, component: AuthCallbackComponent
canActivate: [AuthCallbackGuard],
}, },
{ {
path: 'loggedout', path: 'loggedout',

View File

@ -1,5 +1,7 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { OAuthService } from 'angular-oauth2-oidc';
import { Location} from '@angular/common';
@Component({ @Component({
selector: 'fm-auth-callback', selector: 'fm-auth-callback',
@ -7,6 +9,11 @@ import { Component } from '@angular/core';
}) })
export class AuthCallbackComponent { export class AuthCallbackComponent {
constructor() { constructor(private router$: Router,private oauthService$:OAuthService) {
oauthService$.loadDiscoveryDocument().then(() => {
oauthService$.tryLoginCodeFlow().then(() => {
router$.navigateByUrl((oauthService$.state && oauthService$.state!="")?decodeURIComponent(oauthService$.state):"");
});
})
} }
} }

View File

@ -25,7 +25,7 @@ export class AppCommonEffects {
withLatestFrom(this.store$.select(appCommonReducers.selectGetInitialized)), withLatestFrom(this.store$.select(appCommonReducers.selectGetInitialized)),
mergeMap(([action, initialized]) => { mergeMap(([action, initialized]) => {
var a = (action as appCommonActions.Login); var a = (action as appCommonActions.Login);
this.oauthService$.initImplicitFlow(a.url); this.oauthService$.initCodeFlow(a.url);
return []; return [];
})); }));

View File

@ -27,17 +27,10 @@ export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthS
oauthService.configure(authconfigFactory.getAuthConfig(appConfig)); oauthService.configure(authconfigFactory.getAuthConfig(appConfig));
oauthService.setStorage(authStorage); oauthService.setStorage(authStorage);
oauthService.setupAutomaticSilentRefresh(); oauthService.setupAutomaticSilentRefresh();
let location = injector.get(Location); }).then(() => oauthService.loadDiscoveryDocument()
let router = injector.get(Router); ).then(() => {
let urlPath = location.path();
oauthService.loadDiscoveryDocument().then(() => {
oauthService.tryLoginCodeFlow().then(() => {
router.navigateByUrl((oauthService.state && oauthService.state!="")?decodeURIComponent(oauthService.state):urlPath);
});
})
}).then(() => {
itemtypeService.load(appConfig).then(() => resolve()).catch(() => reject()); itemtypeService.load(appConfig).then(() => resolve()).catch(() => reject());
}); })
}); });
} }
} }

View File

@ -62,7 +62,7 @@ const routes = [
@NgModule({ @NgModule({
imports: [RouterModule.forRoot(routes, imports: [RouterModule.forRoot(routes,
{ initialNavigation: false })], // , enableTracing: true { initialNavigation: true })], // , enableTracing: true
exports: [RouterModule] exports: [RouterModule]
}) })
export class AppRoutingModule { } export class AppRoutingModule { }