Skip to content

Best way to track token/session expiry ? #594

@max-l

Description

@max-l

If have stumbled on a case where AuthenticationManager.authenticated is true, but the underlying tokens expired, and had a failure after calling an api method.

Calling refreshTokens() worked, after calling it, api methods are once again returning expected results.

I wish I could get the exact error I received for "stale tokens", but I have to wait for them to expire, not sure how long that is.

To avoid expired token errors, I need to call "refreshTokens" before every call, wich is unelegant.

I saw that it has a filed named "expires_in", described here : https://docs.globus.org/api/auth/reference/#token-introspect

however, maybe the SDK provides a way to track expiry.

My other question is interpreting the result of refreshTokens, the response is a list of tokens with status, it seems that "fulfilled" means the refresh was successful :

            authorizationManager.refreshTokens().then(res => {
                for (let i = 0; i < res; i++) {
                    if(res[i].status !== "fulfilled") {
                        setIsAuthenticated(false)
                        return
                    }
                }
                setIsAuthenticated(true)
            })

In my case, i treat the existence of a single invalid (or expired) token as "needing to login again".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions