Issue
I am writing an app using Firebase and the Spotify API.
I want my app to use the search endpoint of the Spotify API. The endpoint needs an OAuth token. I am using the Spotify Client credentials authorization to get the bearer token for my app.
I want to let the user call a cloud function via a HTTP request, with the parameters being the name of the song he's searching. The cloud function should be handling all the spotify OAuth stuff and the request to the endpoint. The cloud function should request a new bearer token every hour for the connection between my app and the API to be live. (I will use a CRON job for this).
How should I store the bearer token and its expiration date using cloud functions? I thought about saving them in a Firestore document, but I realized that would mean more document reads and writes just for the usage of the search function of the API.
What should I do in this situation? Where is the place to store such information that expires every hour within a firebase app using cloud functions?
Solution
Did you consider storing the token in a temp file on disk?
While Cloud Functions don't have permanent storage, they do have a writeable temp drive that might fit your needs. While the instance that runs your Cloud Functions (and thus that contains your temp files) could be wiped at any time, it sounds like you could then just reauthenticate with the API when a new instance is spun up and cache that in a temp file again.
Answered By - Frank van Puffelen Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.