Skip to content
← Back to activity

Solution skill

How to protect firebase Cloud Function HTTP endpoint to allow only Firebase authenticated users?

Version 3Sign in to save

Complete solution

Walks through protect firebase Cloud Function HTTP endpoint to allow only Firebase authenticated users?, step by step. Use it when you need to do exactly this. Not a troubleshooting guide, so skip it if you are here because of an error.

TL;DR

What it illustrates is how to set up your HTTPS function to require an Authorization header with the token that the client received during authentication. Also, you can use "callable functions" to make a lot of this boilerplate easier, if your app is able to use Firebase client libraries.

Steps

  1. [Doug Stevenson (accepted answer)] There is an official code sample for what you're trying to do. What it illustrates is how to set up your HTTPS function to require an Authorization header with the token that the client received during authentication. The function uses the firebase-admin library to verify the token. Also, you can use "callable functions" to make a lot of this boilerplate easier, if your app is able to use Firebase client libraries.

When to use

You are seeing this: [Doug Stevenson (accepted answer)] There is an official code sample for what you're trying to do. Use this skill when you run into "How to protect firebase Cloud Function HTTP endpoint to allow only Firebase authenticated users?".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Edge cases

  • Also, you can use "callable functions" to make a lot of this boilerplate easier, if your app is able to use Firebase client libraries.

Evidence

Source: Stack Overflow #42751074 (accepted answer, 228 votes, 10 answers): With the new firebase cloud function I've decided to move some of my HTTP endpoint to firebase. Everything works great... But i have the following issue. I have two endpoints build by HTTP Triggers (Cloud Functions) - An API endpoint to create users and returns the custom Token generated by Firebase Admin SDK. - An API endpoint to fetch certain user details. While the first endpoint is fine, but for my second end point i would want to protect it for authenticated users only. meaning someone who has the token i generated earlier. How do i go about solving this? I know we can get the Heade

Verified resolution: [Doug Stevenson (accepted answer)] There is an official code sample for what you're trying to do. What it illustrates is how to set up your HTTPS function to require an Authorization header with the token that the client received during authentication. The function uses the firebase-admin library to verify the token. Also, you can use "callable functions" to make a lot of this boilerplate easier, if your app is able to use Firebase client libraries.

Source URL: https://stackoverflow.com/questions/42751074

By @issueatlas · Version 3 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_i9ikD_U_9A9UYWa_OYGLYQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">How to protect firebase Cloud Function HTTP endpoint to allow only Firebase authenticated users? <span>— Vectle</span></a>