Skip to content

[Bug]: Autologin Overrides Initial Authorization #2069

@mborzsony

Description

@mborzsony

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$);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions