Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Can someone give an example on how to get config from Http with a standalone configuration #1931

Open
guidoffm opened this issue Apr 26, 2024 · 4 comments
Labels

Comments

@guidoffm
Copy link

The current documentation elaborates how to load the config from Http and it points out how to use it in a standalone config. But I am looking for an example that uses both things at once.

@guidoffm
Copy link
Author

After doing some research I found this code piece works, at least for login:

provideAuth({
      loader: {
        provide: StsConfigLoader,
        useFactory: httpLoaderFactory,
        deps: [HttpClient],
      }
    }),

But I found some issues:

  1. The logoff method does not work. It does not throw an error but nothing happens. For static configuration everything is okay.
  2. If I use the httpLoaderFactory from the documentation page then every call of oidcSecurityService.isAuthenticated() e.g. in the html code causes a new http request to get the config.

To work around the 2nd issue I created my own class for that that includes caching:

import { OpenIdConfiguration, StsConfigLoader } from 'angular-auth-oidc-client';
import { HttpClient } from '@angular/common/http';
import { Observable, Subject, map } from 'rxjs';
import { inject } from '@angular/core';


export class MyStsConfigLoader extends StsConfigLoader {

  private configs = new Subject<OpenIdConfiguration[]>;
  private readonly httpClient = inject(HttpClient);
  /**
   *
   */
  constructor() {
    super();
    console.log('MyStsConfigLoader.constructor');
    this.httpClient.get<{
      clientId: string;
      scope: string;
      authority: string;
    }>(`config/auth-config.json`).pipe(
      map((customConfig) => {

        console.log('customConfig', customConfig);

        const config: OpenIdConfiguration = {
          // authority: 'https://idsvr4.azurewebsites.net',
          redirectUrl: window.location.origin,
          postLogoutRedirectUri: window.location.origin,
          // clientId: 'spa',
          // scope: 'openid profile offline_access', // 'openid profile offline_access ' + your scopes
          responseType: 'code',
          silentRenew: true,
          useRefreshToken: true,
          renewTimeBeforeTokenExpiresInSeconds: 30,
        };

        config.authority = customConfig.authority;
        config.clientId = customConfig.clientId;
        config.scope = customConfig.scope;
        console.log('config', config);
        return [config];
        
      })).subscribe(x => this.configs.next(x));
  }

  override loadConfigs(): Observable<OpenIdConfiguration[]> {
    return this.configs;
  }

}

@krabouilleur
Copy link

The logoff method not working for me. Have you find a solution ?

@guidoffm
Copy link
Author

The logoff method not working for me. Have you find a solution ?

No, I haven't.

@krabouilleur
Copy link

The logoff method not working for me. Have you find a solution ?

No, I haven't.

Is there an alternative ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants