diff --git a/projects/common/src/fm/common-service.module.ts b/projects/common/src/fm/common-service.module.ts index 7acf908..7a0b1a1 100644 --- a/projects/common/src/fm/common-service.module.ts +++ b/projects/common/src/fm/common-service.module.ts @@ -91,7 +91,7 @@ export class AppCommonServiceModule { { provide: APP_INITIALIZER, useFactory: appConfigFactory, - deps: [Injector, AppConfig, OAuthService,AuthConfigFactory], + deps: [Injector, AppConfig, OAuthService,AuthConfigFactory,OAuthStorage], multi: true }, { diff --git a/projects/common/src/fm/common.module.ts b/projects/common/src/fm/common.module.ts index ab43fb2..acade3b 100644 --- a/projects/common/src/fm/common.module.ts +++ b/projects/common/src/fm/common.module.ts @@ -41,6 +41,7 @@ import {IUser} from './models/user'; import * as commonActions from './actions/app-common.actions'; import * as commonReducers from './reducers/app-common.reducer'; import * as commonEffects from './effects/app-common.effects'; +import { SecureOAuthStorage} from './shared/secureOAuthStorage'; export { SafePipe, @@ -67,7 +68,8 @@ export { commonReducers, IAuthconfigFactory, AuthConfigFactory, - MenuBackgroundComponent + MenuBackgroundComponent, + SecureOAuthStorage }; @NgModule({ diff --git a/projects/common/src/fm/shared/app.config.factory.ts b/projects/common/src/fm/shared/app.config.factory.ts index 51ef18e..5bee96e 100644 --- a/projects/common/src/fm/shared/app.config.factory.ts +++ b/projects/common/src/fm/shared/app.config.factory.ts @@ -1,12 +1,13 @@ import { Injector } from '@angular/core'; import { Location} from '@angular/common'; import { Router,UrlSerializer } from '@angular/router'; -import { AuthConfig, OAuthService, JwksValidationHandler, OAuthErrorEvent } from 'angular-oauth2-oidc'; +import { AuthConfig, OAuthService, JwksValidationHandler, OAuthErrorEvent, OAuthStorage } from 'angular-oauth2-oidc'; import { AppConfig } from "./app.config"; import { IAuthconfigFactory } from './authconfigFactory'; -export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthService: OAuthService, authconfigFactory:IAuthconfigFactory): () => Promise { + +export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthService: OAuthService, authconfigFactory:IAuthconfigFactory,authStorage:OAuthStorage): () => Promise { return (): Promise => { return appConfig.load().then(() => { oauthService.events.subscribe((event) => { @@ -22,7 +23,7 @@ export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthS } }); oauthService.configure(authconfigFactory.getAuthConfig(appConfig)); - oauthService.setStorage(localStorage); + oauthService.setStorage(authStorage); oauthService.tokenValidationHandler = new JwksValidationHandler(); oauthService.tokenValidationHandler.validateAtHash = function () { return new Promise((res) => { res(true); }) diff --git a/projects/common/src/fm/shared/secureOAuthStorage.ts b/projects/common/src/fm/shared/secureOAuthStorage.ts new file mode 100644 index 0000000..dc7d336 --- /dev/null +++ b/projects/common/src/fm/shared/secureOAuthStorage.ts @@ -0,0 +1,36 @@ +import {OAuthStorage} from 'angular-oauth2-oidc'; +import {Inject, Injectable} from '@angular/core'; + +@Injectable() +export class SecureOAuthStorage extends OAuthStorage { + private storage = {}; + + secureKey(key:string): boolean { + if(key == "nonce") return false; + if(key == "PKCI_verifier") return false; + return true; + } + + getItem(key: string): string { + if(this.secureKey(key)) { + return this.storage[key]; + } else { + return window.sessionStorage.getItem(key); + } + + }; + removeItem(key: string): void { + if(this.secureKey(key)) { + delete this.storage[key]; + } else { + window.sessionStorage.removeItem(key); + } + } + setItem(key: string, data: string): void { + if(this.secureKey(key)) { + this.storage[key]=data; + } else { + window.sessionStorage.setItem(key,data); + } + } +} \ No newline at end of file diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0d60d8f..b6a57de 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,8 +18,8 @@ import { StoreRouterConnectingModule} from '@ngrx/router-store'; import {AppRoutingModule} from './app-routing.module'; import { LogoComponent } from './logo/logo.component'; import { MenuComponent } from './menu/menu.component'; -import { LocalAuthconfigFactory} from './localAuthconfigFactory'; -import { AuthConfig } from 'angular-oauth2-oidc'; +import { SecureOAuthStorage} from '@farmmaps/common'; +import { OAuthStorage } from 'angular-oauth2-oidc'; export const BOOTSTRAP_EFFECTS = new InjectionToken('Bootstrap Effects'); @@ -62,7 +62,11 @@ export function provideBootstrapEffects(effects: Type[]) { EffectsModule.forRoot([]) ], providers: [ - AuthConfigFactory + AuthConfigFactory, + { + provide:OAuthStorage, + useClass:SecureOAuthStorage + } // { // provide:AuthConfigFactory, // useClass:LocalAuthconfigFactory