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.

/token is not being called sometimes

See original GitHub issue

I have an angular8 application using the Autherization_code work flow here is my auth service

export class AuthService {
  constructor(private oauthService : OAuthService, configurationService: SherpaConfigurationService, private securitiesService: SecuritiesService) { 
    this.oauthService.configure(authConfig);
    this.oauthService.tokenValidationHandler = new JwksValidationHandler();
    this.oauthService.loadDiscoveryDocumentAndLogin();
  }
  login()
  {
    this.oauthService.initCodeFlow();
  }

I have a guard setup basically to check and see if I have an access token in my sessionStorage. If not then call the login() method

export class AuthGuardService implements CanActivate{
  constructor(public router: Router, private authService : AuthService) {}
  canActivate(): boolean {

    if (!sessionStorage.getItem('access_token')) {
      this.authService.login();
      return false;
    }
    return true;
  }
}

I see the /Authorize going out. I get back the code in the redirect_URL then I see /key call going out. But for some reason sometimes I see /token call being made which I get the Access token in return. but most of the time the /token doesn’t get called which result me keep redirecting to the url and my sessionStorage doesn’t get populated with the access_token. What am I doing wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
jelbatnigicommented, Apr 2, 2020

I am sorry if I offended you by saying too complicated. I do really appreciate your help! please don’t get me wrong It is a great solution maybe the reason I find it hard is because I am a beginner to Angular. But I think there must be an easier way to handle this. the few examples that I have seen people using this library didn’t have this problem. If using Async workflow is needed for this library to work properly then this should be documented and addressed, or there should be a built in way to handle this race condition scenario.

1reaction
jeroenheijmanscommented, Apr 2, 2020

No offense taken!

I personally don’t see how most real-world applications using OAuth/OpenID can usefully spin up without doing some async work. But others may have good production-ready examples for that? I think the sample in this repo itself contains some synch logic in the guards.

For me, my sample repo serves as documentation to a degree. It is also linked from the readme, I believe. But, all this stuff is highly dependent on how you mean to write your application, so generic guidance would be really hard.

Good luck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

~/connect/token is not bein called properly - MSDN - Microsoft
The problem is actually the app is not being logged in. Method is unable to call. Sometimes function is being called properly and...
Read more >
Get ASP.NET MVC5 WebAPI token fails sometimes
Run is achieving nothing, so that should go. I understand this is Topshelf app ported over from a console app. I'm not very...
Read more >
Menu token not working sometimes - Drupal Answers
This sounds like your menu item isn't getting cached correctly, it sounds like it doesn't have the right cache contexts. – sonfd. Jun...
Read more >
APNS & VOIP token delegate not… | Apple Developer Forums
Sometimes it occur like this can't receive token, must change network or turn of turn on it will be normal and sometimes receive...
Read more >
OAuth 2.0 with user context: Refresh tokens not working
Without a valid refresh token, there is no way to obtain any new user access tokens, rendering any app using the offline.access scope...
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