AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
585 stars 159 forks source link

renewTokens is missing in new version 6.0.13 #835

Closed 0ctav0 closed 1 year ago

0ctav0 commented 2 years ago

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

guillaume-chervet commented 2 years ago

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

0ctav0 commented 2 years ago

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

guillaume-chervet commented 2 years ago

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

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

0ctav0 commented 2 years ago

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 commented 2 years ago

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 :)

guillaume-chervet commented 2 years ago

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.

NZainchkovskiy commented 2 years ago

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?

guillaume-chervet commented 2 years ago

I will set up the method for your use case

guillaume-chervet commented 2 years ago

On monday

guillaume-chervet commented 2 years ago

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.

0ctav0 commented 2 years ago

@guillaume-chervet Yes, thank you so much!

guillaume-chervet commented 2 years ago

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

NZainchkovskiy commented 2 years ago

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!

tielushko commented 2 years ago

@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

guillaume-chervet commented 1 year ago

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 commented 1 year ago

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

guillaume-chervet commented 1 year ago

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