question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Silent Renew process doesn't always start with a protected route

See original GitHub issue

Describe the bug When using AutoLoginGuard globally, rather than manually using CheckAuth or similar, the silent renew process fails to start until after the user has been reauthenticated at least one time. This leads to the user being redirected to the login page when navigating between secured routes, even after they’ve previously been authenticated.

Once the user has been logged in a second time, the silent renew process usually behaves as intended.

To Reproduce Steps to reproduce the behavior: First ensure you have setup AutoLoginGuards on all routes. Personally, I did something similar to the following:

const appRoutes: Routes = [
  {path: '', pathMatch: 'full', redirectTo: 'home'},
  {path: 'unauthorized', component: UnauthorizedComponent},
  {
    path: 'home',
    canActivate: [AutoLoginGuard],
    loadChildren: () => import('./modules/home/home.module').then(m => m.HomeModule)
  }
  {path: '**', component: PageNotFoundComponent},  // Wildcard route for a 404 page
];

Also ensure silent renew is setup:

export function configureAuth(oidcConfigService: OidcConfigService) {
  return () =>
    oidcConfigService.withConfig({
      stsServer: environment.identity_url,
      redirectUrl: window.location.origin,
      postLogoutRedirectUri: window.location.origin,
      clientId: environment.client_id,
      scope: environment.scope, // must have offline_access scope
      responseType: 'code',
      silentRenew: true,
      useRefreshToken: true,
      logLevel: LogLevel.Debug,
    });
}
  1. Open the WebApp
  2. Clear all site data image
  3. Refresh the page (which should cause the user to be authenticated)
  4. Open the console and notice silent renew is not running image
  5. Wait for the login to timeout and then navigate to another secured route. This should force another sign in.
  6. Once the second authentication process has completed, you should be able to open the console and see the silent renew running. If the silent renew process does not start, I’ve had luck with clearing the cache and refreshing multiple times. image

Expected behavior The silent renew process should always run as soon as the user has been successfully authenticated (and silent renew is enabled).

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: All tested chromium-based browsers (Edge and Chrome)
  • Versions: Edge 90.0.818.46, Chrome 91.0.4472.77

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
FabianGosebrinkcommented, Jun 24, 2021

We fixed this in V12. We are currently in a testing phase and will release V12 afterwards.

1reaction
dbrilscommented, Jun 24, 2021

@FabianGosebrink thanks for the fast response 😊 I wasn’t sure if it was related, but I’m glad it will be fixed in v12! 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

During silent renew process failure your App can fully hang
Our team faced with an issue when our users can't open our App. Steps to reproduce: OIDC flow: authorization code; Turn on silent...
Read more >
Configure Silent Authentication - Auth0
Learn how to keep users logged in to your application using silent authentication.
Read more >
ReactJS - Silently renew token with iframe - Stack Overflow
In silenwRenew method, the redirectUrl needs to be retrieved from the localStorage , this is the URL what you are going to store...
Read more >
Persistent login in React using refresh token rotation
In this tutorial, you can learn how to use refresh tokens in React to facilitate infinitely long login sessions.
Read more >
OpenID Connect with Angular 8 (OIDC Part 7)
Requests the right tokens and scopes; Does the right redirects; Knows how to locate the endpoints on the authorization server; Is doing silent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found