globus / globus/globus-sdk-javascript

Best way to track token/session expiry ?

Open
#594 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11
Forks
4
Avg merge
1d 21h
Merged PRs (30d)
10

Description

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".

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.