简体   繁体   中英

Where to store API access token?

I am using an API ( https://developers.gfycat.com/api/ ) that uses the typical OAuth flow to grant developers access to API requests. I am able to successfully simulate the entire process of getting an access token and using it in an API request by manually plugging in the values throughout my code. Now that I have all the moving parts successfully working, I am trying to put all the pieces together and have some questions:

A successful request for the API access token looks like this:

{"token_type":"bearer","scope":"","expires_in":3600,"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NDM5NTIzOTEsImlzcyI6IjJfWldiaktHIiwicm9sZXMiOlsiQ29udGVudF9SZWFkZXIiXX0.SFdMGS8J_KP7pM2H33eu3l6ip2-8PkVHM4VTZzxTWyw"}
  1. Is it best to retrieve the access token once at app launch, then store the access token somewhere, and then every time I try making an API request ensure that I catch any "access token expired" errors before attempting to retrieve an access token? Or is it acceptable to simply make a request for the access_token each and every time I make an API request, even if it's very frequently?

  2. Where in my app do I store the access_token field if I decide to go that route?

  1. create a column in table of database to save the token,but it's kinda annoying because every time when you need to update your token , you have to write to databases again.
  2. you can search "Redis", I think it can help you more suitable to save the token

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM