Search code examples
angularopenshiftopenid-connectangular-oauth2-oidc

get config values using http in angular-auth-oidc-client


I have this environment file in angular :

export const environment = {
  production: false,
  apiVersion: 'v1',
  apiBaseUrl: 'http://localhost:8080/api',
  Access_Control_Allow_Origin: 'http://my-app-back:8080',
  oidc: {
    authority: '',
    redirectUrl: window.location.origin,
    postLogoutRedirectUri: window.location.origin,
    clientId: '',
    scope: 'openid profile email offline_access',
    responseType: 'code',
    silentRenew: false,
    useRefreshToken: true,
    renewTimeBeforeTokenExpiresInSeconds: 30,
    logLevel: LogLevel.Debug,
    secureRoutes: ['/api/'],
    autoUserInfo: false,
  },
};

i want to set the authority and client_id values using http request please, thanks.

i don't know how to achieve this in angular, i saw examples using services but didn't work for me


Solution

  • If it's in the build of the app, you need, for example, use NODE script to make the request to the API and rewrite the environment file and then execute the build command and then you will have your app with the values ​​you need from the API. On the other hand, if it's on runtime you have 2 options:

    • 1- You would have to change "export const" for "export let" so that it allows you to alter the variable.
    • 2- Use a BehaviorSubject that allows you to have initial values ​​and when you receive the response from the API you can update to the variable which is an Observable and works very well with Angular.