diff --git a/apps/restorecommerce/src/app/app.module.ts b/apps/restorecommerce/src/app/app.module.ts index 62582db2..4a568f93 100644 --- a/apps/restorecommerce/src/app/app.module.ts +++ b/apps/restorecommerce/src/app/app.module.ts @@ -32,6 +32,10 @@ import { RoutesTitleStrategyService } from './routes-title-strategy.service'; VCLProgressBarModule, ], providers: [ + { + provide: 'oidcKey', + useValue: environment.oidcKey, + }, { provide: 'apiUrl', useValue: environment.urls.api, diff --git a/packages/core/config/src/lib/constants/authn.ts b/packages/core/config/src/lib/constants/authn.ts index a36e0b96..1a82b191 100644 --- a/packages/core/config/src/lib/constants/authn.ts +++ b/packages/core/config/src/lib/constants/authn.ts @@ -1,9 +1,7 @@ -import { IAuthnConstant } from '@console-core/types'; +import { TAuthnConstant } from '@console-core/types'; -export const AUTH: Readonly = { - headers: { - Accept: 'application/json', - 'Content-type': 'application/x-www-form-urlencoded', - Authorization: 'Basic VEVTVF9DTElFTlRfSUQ6VEVTVF9DTElFTlRfU0VDUkVU=', - }, -}; +export const AUTH = (key: string): Readonly => ({ + Accept: 'application/json', + 'Content-type': 'application/x-www-form-urlencoded', + Authorization: `Basic ${key}`, +}); diff --git a/packages/core/state/src/lib/services/identity/authn.service.ts b/packages/core/state/src/lib/services/identity/authn.service.ts index c2ea68ad..a428c314 100644 --- a/packages/core/state/src/lib/services/identity/authn.service.ts +++ b/packages/core/state/src/lib/services/identity/authn.service.ts @@ -1,5 +1,5 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { Injectable } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { MutationResult } from 'apollo-angular'; import { Observable } from 'rxjs'; @@ -21,9 +21,10 @@ import { ApiService } from '../api.service'; providedIn: 'root', }) export class AuthnService { - private readonly headers = new HttpHeaders(AUTH.headers); + private readonly headers = new HttpHeaders(AUTH(this.oidcKey)); constructor( + @Inject('oidcKey') private oidcKey: string, private readonly httpClient: HttpClient, private readonly apiService: ApiService, private readonly identityUserRegisterGQL: IdentityUserRegisterGQL diff --git a/packages/core/types/src/lib/types/authn.ts b/packages/core/types/src/lib/types/authn.ts index fab1c795..6161028f 100644 --- a/packages/core/types/src/lib/types/authn.ts +++ b/packages/core/types/src/lib/types/authn.ts @@ -1,7 +1,13 @@ import { IAuthnState, IStoreConstant } from '../interfaces'; -type AuthnStateKey = IStoreConstant['states']['authnState']; +type TAuthnStateKey = IStoreConstant['states']['authnState']; -export type IAuthnStateType = { - [key in AuthnStateKey]: IAuthnState; +export type TAuthnStateType = { + [key in TAuthnStateKey]: IAuthnState; +}; + +export type TAuthnConstant = (key: string) => { + Accept: string; + 'Content-type': string; + Authorization: string; };