amazon-cognito-auth-js icon indicating copy to clipboard operation
amazon-cognito-auth-js copied to clipboard

No callback for getSession, how to deal with refresh?

Open raf202 opened this issue 7 years ago • 3 comments

I've been looking into the token refresh flow, what I would do is always call getSession with a callback to my API calls, that would make sure that my token is always valid. But I noticed in the code that getSession does not provide any callback functions.

How is the workflow to approach refresh without a callback? Setting up a timer to auto refresh seems a bit hacky to me.

raf202 avatar Apr 09 '18 00:04 raf202

await and promises AFAIK doesn't work as getSession will complete immediately even when it takes 2-3 seconds for the token to be refreshed.

erwinkarim avatar Apr 16 '18 21:04 erwinkarim

I had the same issue. Instead of calling getSession, I checked if session is not valid and we have a refresh token, then call the https://{{appDomain}}/oauth2/token api directly with these parameters header: 'Content-Type': 'application/x-www-form-urlencoded' body: 'grant_type=refresh_token&client_id=${clientId}&refresh_token=${refreshToken}' using the Fetch API. In the then block, I passed the result to onSuccessExchangeForToken method found in this SDK.

aswin1689 avatar Apr 20 '18 20:04 aswin1689

userhandler onSuccess or onFailure is called for getSession.

jollsker avatar Apr 27 '18 09:04 jollsker