-
Notifications
You must be signed in to change notification settings - Fork 232
authState.isAuthenticated
is not updated properly when either idToken
or accessToken
is expired
#721
Comments
Good catch @Valdermeyder! I have to add a quick test to the PR, but we'll definitely be fixing this ASAP! |
Internal ref: OKTA-288352 |
@Valdermeyder - We've reverting this change, as internal discussions reveal that this is the intended behavior. The issue appears to be confusion as to what "isAuthenticated" means. We are reviewing our docs to make that more clear, since (as you point out) what is said is NOT specifically what is happening. Renewal of tokens should be automatic, customers can configure them to have different lifespans for different purposes. Currently you can override In order to make sure your use-case is covered, can you share a bit more about how you found problems with this (aside from manually deleting tokens from localStorage)? |
Well not sure about the OP’s issue but at least on my side when the accessToken is expired i don’t get a new token unless i refresh the browser on the SecureRoute. I have a useEffect listening to authState and it never gets called. And autoRenew is true on my side. Therefore when i send that accessToken requests to the api server it fails with 401. If isAuthenticated is as designed then it would be nice to have something in authState that indicates tokens are expired and triggers our useEffect so we can act on that. I’m on version 2.0.1 for okta-react. 3.0.0’s /implicit/callback route doesn’t work. I created a separate issue for that. |
@swiftone in my particular case the the |
@sero323 - I'm curious about the issues you are experiencing with autoRenew - as designed, it SHOULD autoRenew. Are you overriding the default onSessionExpired() call? Do you have a separate issue for this autorenewal problem? |
@swiftone, no i don't have a separate issue (i can create one if you'd like). But again, i'm using the signin widget, along with okta-react 3.0, mobx, hash router. Here's my configuration...
and also, here's how i have "Protected" component setup...
|
@Valdermeyder - We're working to make sure we have a consistent and understandable definition of |
@swiftone thanks for the help. |
Hey @swiftone, I'm curious about the definition of I followed this tutorial and it ecommends using I would be down to use Am I missing something? Thanks in advance for taking the time to explain 🙂 |
@sarahdayan - Happy to answer what I can:
The problem here is "what does it mean to be 'authenticated'?". The code currently says something like: "If you have either a valid access token or a valid id token, that means you successfully proved your authentication and don't yet need to do it again". But often those two tokens have different expiration dates. And if (for example), your idToken expired but your accessToken hasn't, does that mean you are or are not "authenticated"? Today, the code says you are, and (as you discover), that stinks if you then rely on this to mean the idToken remains valid. (Of course, if you aren't relying on that, using a "requires both tokens" definition means users will be reauthenticated more frequently) One solution is to use the override for Another solution is to explicitly check what you are relying on, such as confirming that authState.idToken is present before relying upon it. In upcoming major versions we hope to clarify (or remove) the confusion in the labels, but for now, the above options are the ones that you have. Does that address your question? |
I'm submitting this issue for the package(s):
I'm submitting a:
Current behavior
When the user doesn't have
idToken
(it became expired) theauthState.isAuthenticated
property still has the valuetrue
The issue looks like come from this code
which contains code which doesn't align with the documentation "By default, authService will consider a user authenticated if both getIdToken() and getAccessToken() return a value"
Expected behavior
When the user doesn't have either
idToken
oraccessToken
theauthState.isAuthenticated
property should have valuefalse
Minimal reproduction of the problem with instructions
idToken
fromokta-token-storage
inside Application -> Local Storage (default place for tokens)You should be redirected to the login page, but it doesn't happen and if you show some information using
authService.getUser()
method it will not be visibleExtra information about the use case/user story you are trying to implement
I have created pull-request with quick fix #718 but some tests are failed and now I have doubts if this correct solution
Workaround
For versions 2.x and 3.x
Environment
node -v
): v13.10.1The text was updated successfully, but these errors were encountered: