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

[Bug]: Autologin Overrides Initial Authorization #2069

Open
mborzsony opened this issue Jan 21, 2025 · 1 comment
Open

[Bug]: Autologin Overrides Initial Authorization #2069

mborzsony opened this issue Jan 21, 2025 · 1 comment

Comments

@mborzsony
Copy link

Version

^18.0.1

Please provide a link to a minimal reproduction of the bug

NA

Please provide the exception or error you saw

NA

Steps to reproduce the behavior

NA

A clear and concise description of what you expected to happen.

We have a usecase where a inital request for a user registration contains a login_hint. 
On initialization the application does a checkAuth and validates the login_hint is present in the request and proceeds with a authorize request. 
The AutoLoginPartialRoutesGuard overides the Inital Request.

Additional context

app.component.ts:

  ngOnInit() {
    this.authService.checkAuth().subscribe(({ isAuthenticated}) => {
      if(!isAuthenticated){
        this.login();
      }else{
        this.loading = false;
      }
    });
  }

  login(){
    let url: URL =  new URL(window.location.href);
    let hint = url.searchParams.get('login_hint')?.toString();
    if(!!hint){
      this.authService.authorize('',{ customParams: { login_hint: `${hint}` }});
    }else{
      this.authService.authorize()
    }
  }

app.routes.ts:

export const routes: Routes = [
  { path: '', redirectTo: 'dashboards', pathMatch: 'full' },
  { path: 'callback', component: CallbackComponent },
  {
    path: 'dashboards',
    loadChildren: () =>
      import('../app/si-modules/si-dashboards/si-dashboards.module').then(
        (module) => module.SiDashboardsModule
      ),
    data: { breadcrumb: 'Dashboards' },
    canActivate: [AutoLoginPartialRoutesGuard],
  },

Configuration:

export const httpLoaderFactory = (httpClient: HttpClient) => {
    
    const config$ = TenantSettings(httpClient).pipe(
        map((response: any) => {
            return {
                postLoginRoute: '/dashboards',
                authority: response.authority,
                redirectUrl: `${window.location.origin}/callback`,
                postLogoutRedirectUri: window.location.origin,
                clientId: response.clientId,
                scope: response.scope,
                responseType: response.responseType,
                silentRenew: response.silentRenew, //true
                useRefreshToken: response.useRefreshToken, //true
                logLevel: LogLevel.Debug,
                triggerRefreshWhenIdTokenExpired: true,
                ignoreNonceAfterRefresh: true,
            };
        })
    );

    return new StsConfigHttpLoader(config$);
};
@mborzsony
Copy link
Author

Here is the network behavior:

Image

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

No branches or pull requests

1 participant