Answered by:
How can I keep track of API token expiration

Question
-
User1122679459 posted
Hi,
I'm working with an API that returns an access token and an expiration of 60 minutes. I created a @functions that returns the token but I can't figure out how I can keep track when the token expires.
So in my application, how can I keep track of when it expires? ...then I can just request another one.
This is the json the api returns:
{ "token_type": "bearer", "expires_in": 3600, "refresh_token": "xxx", "access_token": "xxx" }
Saturday, November 10, 2018 1:57 PM
Answers
-
User475983607 posted
Hi,
I'm working with an API that returns an access token and an expiration of 60 minutes. I created a @functions that returns the token but I can't figure out how I can keep track when the token expires.
So in my application, how can I keep track of when it expires? ...then I can just request another one.
This is the json the api returns:
{ "token_type": "bearer", "expires_in": 3600, "refresh_token": "xxx", "access_token": "xxx" }
It is up to the client to read the token expiration and request a refresh or a new access token. It is not clear why you are unable to read the access token expiration and compare the token expiration to the current DateTime.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, November 10, 2018 2:19 PM -
User61956409 posted
Hi Alvin,
I created a @functions that returns the token but I can't figure out how I can keep track when the token expires.If you'd like to trace the status/expiration of your access token in web application, you can create and run a web worker in the background, which could perform tasks without interfering with the user interface.
After you retrieved the token. you can start a timer based on expiration of token by using setTimeout() method, and request another one via refresh_token before it reaches expiration time.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, November 13, 2018 5:40 AM
All replies
-
User475983607 posted
Hi,
I'm working with an API that returns an access token and an expiration of 60 minutes. I created a @functions that returns the token but I can't figure out how I can keep track when the token expires.
So in my application, how can I keep track of when it expires? ...then I can just request another one.
This is the json the api returns:
{ "token_type": "bearer", "expires_in": 3600, "refresh_token": "xxx", "access_token": "xxx" }
It is up to the client to read the token expiration and request a refresh or a new access token. It is not clear why you are unable to read the access token expiration and compare the token expiration to the current DateTime.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, November 10, 2018 2:19 PM -
User61956409 posted
Hi Alvin,
I created a @functions that returns the token but I can't figure out how I can keep track when the token expires.If you'd like to trace the status/expiration of your access token in web application, you can create and run a web worker in the background, which could perform tasks without interfering with the user interface.
After you retrieved the token. you can start a timer based on expiration of token by using setTimeout() method, and request another one via refresh_token before it reaches expiration time.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, November 13, 2018 5:40 AM