I would like to serve static content using cloud flare cdn, But it should be accessible only to authenticated user. Now the resource is kept in firebase storage and following this tutorial. https://www.ayrshare.com/how-to-put-a-cdn-in-front-of-firebase-cloud-storage/.
But this avail the bucket accessible to public. I would like to do this
https://blog.cloudflare.com/token-authentication-for-cached-private-content-and-apis/ but if i store it in google cloud storage it will be accessible to public. Is there any alternative way to serve static content protected?
CodePudding user response:
You can create a Worker which will run on your Cloudflare domain (at a configured route) and then pull the required assets from Google Cloud using authentication between the Worker and Google Cloud.
There are several code samples here showing how to use the Fetch API. Also here to see other examples showing you how to use the Cache API in Workers to serve the content from the CDN instead of pulling it every time from Google Cloud.