angular-auth-oidc-client icon indicating copy to clipboard operation
angular-auth-oidc-client copied to clipboard

[Bug]: Silent refresh fails using localStorage when multiple tabs trying to refresh at the same time

Open Coldfen opened this issue 2 years ago • 16 comments

Version

16.0.0

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

myConfigId - silent renew failed! Error: Error: authorizedCallback, token(s) validation failed, resetting.

Steps to reproduce the behavior

1) Set up OIDC Code Flow PKCE using refresh tokens (used 'ng add angular-auth-oidc-client')

2) Set up custom storage using localStorage (used example from https://angular-auth-oidc-client.com/docs/documentation/custom-storage)

3) To speed up testing, setup your authority to have short lived access and refresh tokens. (i.e. 30 - 50 seconds) 

4) Login using one browser [chrome] tab (i.e. this.oidcSecurityService.authorize()). Open console and verify refresh is working

5) Open a few more tabs. Open console and verify they are authorized and refreshing (in my case i open 6 or more)

6) Wait until error occurs. It shouldn't take long - usually 2-20 minutes with 30 - 40 seconds tokens. Open more tabs if needed.

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

Access token should refresh successfully and all tabs remain authorized

Additional context

The same problem was described in #1662

image

A temporary solution does not suit me well, because my token functions for 300 seconds.

My config: image

AuthConfigModule added to the imports of the main AppModule.

Coldfen avatar Sep 13 '23 12:09 Coldfen

Experiencing the same issue. Any help appreciated.

joewIST avatar Sep 19 '23 11:09 joewIST

Same issue.

CraigGP1 avatar Sep 20 '23 06:09 CraigGP1

We're encountering issues with this fairly often too. If there's a solution at the library level, that would be great.

Ghostbird avatar Sep 20 '23 12:09 Ghostbird

Not sure if you are experiencing any of the issues found here as well? https://github.com/damienbod/angular-auth-oidc-client/issues/1753

joewIST avatar Sep 20 '23 14:09 joewIST

No, not as far as I know. The trick mentioned in https://github.com/damienbod/angular-auth-oidc-client/issues/1662#issuecomment-1516305881 is something I'm going to try, where the renewTimeBeforeTokenExpiresInSeconds gets a random number. That won't fix it, but may significantly reduce the problem.

Ghostbird avatar Sep 21 '23 06:09 Ghostbird

Good luck. We tried that in the past but it didn't fix our issue.

joewIST avatar Sep 21 '23 08:09 joewIST

We tried that but unfortunately it doesn't resolve our issue.

joewIST avatar Sep 21 '23 15:09 joewIST

Is there any progress on this issue?

lemonCMS avatar Apr 02 '24 10:04 lemonCMS

The cleanest solution would be to queue up the refreshes to guarantee a sequential order🤔🤔🤔 If that is possible. Have to test, but afair the tab gets a new instance of the lib, so basically we have to distinguish between what is being renewed currently. Maybe we can move the renewal information to the specific entry in the LS. Wdyt?

FabianGosebrink avatar Apr 02 '24 11:04 FabianGosebrink

We have the same issue :/ (v. 16.0.1)

sebastiandenis avatar Apr 04 '24 08:04 sebastiandenis

@FabianGosebrink I think most proposed workarounds are trying to achieve this. I tried a random renewTimeBeforeTokenExpiresInSeconds for example, assuming that it would sequence the refreshes, but that didn't work.

Ghostbird avatar Apr 10 '24 09:04 Ghostbird

@FabianGosebrink is there any chance to fix this anytime soon? We've tried many workarounds, but it seems that you can't do too much from the outside of the lib. When this error occurs, the auth data is being reset in the local storage and it affects all the tabs.

sebastiandenis avatar Apr 24 '24 08:04 sebastiandenis

I would love to but lacking of time :( As soon as I got time I can try to fix this.

FabianGosebrink avatar Apr 24 '24 08:04 FabianGosebrink

Hi @FabianGosebrink, could you give us a hint in how you think this should be implemented?

I was looking at the implementation suggested on the manfredsteyer/angular-oauth2-oidc using the Lock API

https://github.com/manfredsteyer/angular-oauth2-oidc/pull/1423

Trying to replicate it on this library, but i am currently stuck on linking this library into my application locally with this error. I don't have a clue why this might be happening

image

Anyway, if you could share your thoughts on this approach, thank you in advanced ^^

jugarpeupv avatar Aug 05 '24 10:08 jugarpeupv