Refactor authentication flow
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good Details

feature/MinimizeSolution
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 = [
{
path: 'cb',
component: AuthCallbackComponent,
canActivate: [AuthCallbackGuard],
component: AuthCallbackComponent
},
{
path: 'loggedout',

View File

@ -1,12 +1,19 @@
import { Component } from '@angular/core';
@Component({
selector: 'fm-auth-callback',
template:'<div></div>'
})
export class AuthCallbackComponent {
constructor() {
}
}
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { OAuthService } from 'angular-oauth2-oidc';
import { Location} from '@angular/common';
@Component({
selector: 'fm-auth-callback',
template:'<div></div>'
})
export class AuthCallbackComponent {
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)),
mergeMap(([action, initialized]) => {
var a = (action as appCommonActions.Login);
this.oauthService$.initImplicitFlow(a.url);
this.oauthService$.initCodeFlow(a.url);
return [];
}));

View File

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

View File

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