angular-auth-oidc-client
angular-auth-oidc-client copied to clipboard
[Question]: Can someone give an example on how to get config from Http with a standalone configuration
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.
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:
- The logoff method does not work. It does not throw an error but nothing happens. For static configuration everything is okay.
- If I use the
httpLoaderFactoryfrom the documentation page then every call ofoidcSecurityService.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;
}
}
The logoff method not working for me. Have you find a solution ?
The logoff method not working for me. Have you find a solution ?
No, I haven't.
The logoff method not working for me. Have you find a solution ?
No, I haven't.
Is there an alternative ?