Refactor authconfig
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
This commit is contained in:
parent
e1fef2d7f3
commit
560c426bc0
@ -52,6 +52,7 @@ import * as commonReducers from './reducers/app-common.reducer';
|
|||||||
import * as commonEffects from './effects/app-common.effects';
|
import * as commonEffects from './effects/app-common.effects';
|
||||||
import {NgbDateNativeAdapter} from './services/date-adapter.service'
|
import {NgbDateNativeAdapter} from './services/date-adapter.service'
|
||||||
import { from } from 'rxjs';
|
import { from } from 'rxjs';
|
||||||
|
import {AuthConfigFactory} from './shared/authconfigFactory';
|
||||||
|
|
||||||
export {FolderService,
|
export {FolderService,
|
||||||
ItemTypeService,
|
ItemTypeService,
|
||||||
@ -90,7 +91,7 @@ export class AppCommonServiceModule {
|
|||||||
{
|
{
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
useFactory: appConfigFactory,
|
useFactory: appConfigFactory,
|
||||||
deps: [Injector, AppConfig, OAuthService],
|
deps: [Injector, AppConfig, OAuthService,AuthConfigFactory],
|
||||||
multi: true
|
multi: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@ import { MODULE_NAME } from './module-name';
|
|||||||
|
|
||||||
//components
|
//components
|
||||||
import { SafePipe } from './shared/safe.pipe';
|
import { SafePipe } from './shared/safe.pipe';
|
||||||
|
import { AuthConfigFactory,IAuthconfigFactory} from './shared/authconfigFactory';
|
||||||
import { AppComponent} from './components/app/app.component';
|
import { AppComponent} from './components/app/app.component';
|
||||||
import { AuthCallbackComponent } from './components/auth-callback/auth-callback.component';
|
import { AuthCallbackComponent } from './components/auth-callback/auth-callback.component';
|
||||||
import { SessionClearedComponent } from './components/session-cleared/session-cleared.component';
|
import { SessionClearedComponent } from './components/session-cleared/session-cleared.component';
|
||||||
@ -62,7 +63,9 @@ export {
|
|||||||
ITypeaheadItem,
|
ITypeaheadItem,
|
||||||
IUser,
|
IUser,
|
||||||
commonActions,
|
commonActions,
|
||||||
commonReducers
|
commonReducers,
|
||||||
|
IAuthconfigFactory,
|
||||||
|
AuthConfigFactory
|
||||||
};
|
};
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@ -2,22 +2,10 @@ import { Injector } from '@angular/core';
|
|||||||
import { Router,UrlSerializer } from '@angular/router';
|
import { Router,UrlSerializer } from '@angular/router';
|
||||||
import { AuthConfig, OAuthService, JwksValidationHandler, OAuthErrorEvent } from 'angular-oauth2-oidc';
|
import { AuthConfig, OAuthService, JwksValidationHandler, OAuthErrorEvent } from 'angular-oauth2-oidc';
|
||||||
import { AppConfig } from "./app.config";
|
import { AppConfig } from "./app.config";
|
||||||
|
import { IAuthconfigFactory } from './authconfigFactory';
|
||||||
|
|
||||||
function getAuthConfig(appConfig: AppConfig): AuthConfig {
|
|
||||||
let authConfig: AuthConfig = new AuthConfig();
|
|
||||||
authConfig.issuer = appConfig.getConfig("issuer");
|
|
||||||
authConfig.redirectUri = window.location.origin + "/cb";
|
|
||||||
authConfig.silentRefreshRedirectUri = window.location.origin + "/silent-refresh.html";
|
|
||||||
authConfig.clientId = appConfig.getConfig("clientId");
|
|
||||||
authConfig.customQueryParams = { audience: appConfig.getConfig("audience") };
|
|
||||||
authConfig.scope = "openid profile email";
|
|
||||||
authConfig.oidc = true;
|
|
||||||
authConfig.disableAtHashCheck = true;
|
|
||||||
authConfig.requireHttps = appConfig.getConfig("requireHttps");
|
|
||||||
return authConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthService: OAuthService): () => Promise<any> {
|
export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthService: OAuthService, authconfigFactory:IAuthconfigFactory): () => Promise<any> {
|
||||||
return (): Promise<any> => {
|
return (): Promise<any> => {
|
||||||
return appConfig.load().then(() => {
|
return appConfig.load().then(() => {
|
||||||
oauthService.events.subscribe((event) => {
|
oauthService.events.subscribe((event) => {
|
||||||
@ -32,7 +20,7 @@ export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
oauthService.configure(getAuthConfig(appConfig));
|
oauthService.configure(authconfigFactory.getAuthConfig(appConfig));
|
||||||
oauthService.tokenValidationHandler = new JwksValidationHandler();
|
oauthService.tokenValidationHandler = new JwksValidationHandler();
|
||||||
oauthService.tokenValidationHandler.validateAtHash = function () {
|
oauthService.tokenValidationHandler.validateAtHash = function () {
|
||||||
return new Promise<boolean>((res) => { res(true); })
|
return new Promise<boolean>((res) => { res(true); })
|
||||||
|
22
projects/common/src/fm/shared/authconfigFactory.ts
Normal file
22
projects/common/src/fm/shared/authconfigFactory.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { AuthConfig } from 'angular-oauth2-oidc';
|
||||||
|
import {AppConfig} from './app.config';
|
||||||
|
|
||||||
|
export interface IAuthconfigFactory {
|
||||||
|
getAuthConfig(appConfig: AppConfig): AuthConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AuthConfigFactory implements IAuthconfigFactory {
|
||||||
|
getAuthConfig(appConfig: AppConfig): AuthConfig {
|
||||||
|
let authConfig: AuthConfig = new AuthConfig();
|
||||||
|
authConfig.issuer = appConfig.getConfig("issuer");
|
||||||
|
authConfig.redirectUri = window.location.origin + "/cb";
|
||||||
|
authConfig.silentRefreshRedirectUri = window.location.origin + "/silent-refresh.html";
|
||||||
|
authConfig.clientId = appConfig.getConfig("clientId");
|
||||||
|
authConfig.customQueryParams = { audience: appConfig.getConfig("audience") };
|
||||||
|
authConfig.scope = "openid profile email";
|
||||||
|
authConfig.oidc = true;
|
||||||
|
authConfig.disableAtHashCheck = true;
|
||||||
|
authConfig.requireHttps = appConfig.getConfig("requireHttps");
|
||||||
|
return authConfig;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user