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

renewTokens is missing in new version 6.0.13

Open 0ctav0 opened this issue 2 years ago • 14 comments

Issue and Steps to Reproduce

useOidc Hook doesnt have a renewTokens method. I need it for refresh token when getting 401 status code error

This hook should be merged in this PR https://github.com/AxaGuilDEv/react-oidc/pull/778

Versions

6.0.13

Screenshots

image

Expected

Expected to be exported in useOidc hook

Actual

Additional Details

  • Installed packages:

0ctav0 avatar Aug 18 '22 13:08 0ctav0

Hi @0ctav0 , thank you for your issue. You use case interrested me to rebuild this method in v6. Why do you need to renew? Do you need token renew or silent token renew? I want to rebuild it cleanly. Do you need to update extra when you renew?

I have cleanner silent renew it will be easier to rebuild it cleanly now.

Regards

guillaume-chervet avatar Aug 18 '22 15:08 guillaume-chervet

Yes I need silent token renew. Honestly I dont know what is extra?

0ctav0 avatar Aug 18 '22 15:08 0ctav0

Hi @0ctav0 , silent signing occurs automaticaly in background before tokens expires.

You do not need to manage anything once you are login in.

guillaume-chervet avatar Aug 18 '22 20:08 guillaume-chervet

No I have to. I can have situations when by some reason token becomes invalid, which this library can not detect in all possible situations, so I need to manualy renew token when getting 401 error.

0ctav0 avatar Aug 19 '22 05:08 0ctav0

In v3 there was a way to manualy renew tokens. It was helpful and works fine, but since updating to v4, v5 this is headeache, my application becomes unstable in way of authorization and token management. I had to update this library from v3 to v5 because I had to update to react v18 :)

0ctav0 avatar Aug 19 '22 05:08 0ctav0

Hi @0ctav0 , i may need more information about your pro lin order to help you. Like code sample or something else. You do not need to manage token renew in v6. It is done automaticaly.

guillaume-chervet avatar Aug 19 '22 08:08 guillaume-chervet

Seems that auto renewal works only based on expiration time. But there is much more reasons for 401. For example, some of api returns 401 with error Bearer error="invalid_token", error_description="The signature key was not found" if identity server resets. Next token is ok, so if we can renew token when api tell us that token invalid (because of any reason) - there is no problem. Token is invalid - ok, we are getting another one and we are good. At v3 it was possible. Starting with v4 there is no such method. Can you suggest some solution/workaround for our problem?

NZainchkovskiy avatar Aug 19 '22 13:08 NZainchkovskiy

I will set up the method for your use case

guillaume-chervet avatar Aug 19 '22 15:08 guillaume-chervet

On monday

guillaume-chervet avatar Aug 19 '22 15:08 guillaume-chervet

Version 6.3.0 set up renewTokens() method again :)

Does it work for your use case @0ctav0 @NZainchkovskiy ?

I will add possibility to update "extras" in another PullRequest.

guillaume-chervet avatar Aug 22 '22 13:08 guillaume-chervet

@guillaume-chervet Yes, thank you so much!

0ctav0 avatar Aug 23 '22 14:08 0ctav0

Hi @0ctav0 @NZainchkovskiy may I close this Pull Request? Thank you very much for the issue ans feedback :)

guillaume-chervet avatar Sep 07 '22 09:09 guillaume-chervet

Hi @0ctav0 @NZainchkovskiy may I close this Pull Request? Thank you very much for the issue ans feedback :)

Sure, yes. Thank you for your incredible work!

NZainchkovskiy avatar Sep 07 '22 09:09 NZainchkovskiy

@guillaume-chervet Thank you for introducing this feature back! It will be very helpful for implementing the re-fetch of the token when the user switches back to the tab. However, occasionally I've been noticing timeouts coming from oidc.ts file.

The timeout setting for oidc silent renew that I used in configuration is 15 seconds. I wonder what could possibly affect my configuration that it wouldn't reach the Identity server? Besides, does the renewTokens return a promise which has the new token?

MicrosoftTeams-image

tielushko avatar Sep 16 '22 19:09 tielushko

hi @tielushko , sorry I missed your message. This error happen in general when computer is in sleep mode or reconeccting from a VPN.

guillaume-chervet avatar Nov 30 '22 15:11 guillaume-chervet

Do you have more information about the context of when and why it happen?

guillaume-chervet avatar Nov 30 '22 15:11 guillaume-chervet

Hi @0ctav0 , i close the issue. Thank you very much for it. Feel free to reopen it if you needed it.

guillaume-chervet avatar Feb 05 '23 07:02 guillaume-chervet