PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 4, 2022

[FIXED] How can I store a bearer token and it's expiration date using Firebase cloud functions?

 September 04, 2022     authentication, firebase, google-cloud-functions, spotify     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing