damienbod / angular-auth-oidc-client

npm package for OpenID Connect, OAuth Code Flow with PKCE, Refresh tokens, Implicit Flow
https://www.npmjs.com/package/angular-auth-oidc-client
MIT License
1.11k stars 418 forks source link

[Feature Request]: Option for authCheck during app initialization phase #1926

Open kyubisation opened 1 month ago

kyubisation commented 1 month ago

Is your feature request related to a problem? Please describe. Currently the OidcSecurityService.checkAuth() is recommended to be called in the AppComponent, which is a sensible default. However I would prefer to have an option to call it during app initialization (with a provider for APP_INITIALIZER).

Describe the solution you'd like I would like to have an optional possibility to run the auth check during the app initialization phase.

e.g.

export function withAppInitializerAuthCheck() {
  return {
    provide: APP_INITIALIZER,
    useFactory: (oidcSecurityService: OidcSecurityService) => () =>
      oidcSecurityService.checkAuthMultiple(),
    multi: true,
    deps: [OidcSecurityService],
  };
}

...
provideAuth(authConfig, withAppInitializerAuthCheck()),
...

// or alternatively

export interface PassedInitialConfig {
    config?: OpenIdConfiguration | OpenIdConfiguration[];
    loader?: Provider;
    appInitializerAuthCheck?: boolean;
}

Describe alternatives you've considered Just use the code above in my apps.

Additional context I am aware that this is mostly a convenience functionality. Due to this I am more that willing to contribute the necessary code, if this feature is an acceptable addition and there is agreement on the API.