Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Authenticating Firebase users on Google Functions

Hi everyone,

I use Firebase authentication for my React Native App. Once users are registered an logged-in, they can send a request to a Google function:
- the App sets the Authorization bearer in request header with JWT token
- the Function checks the JWT validity with firebase_admin auth.verify_id_token() function

If my function HTTPS trigger is set on :
-> Allow unauthenticated invocations : everything works fine the token is validated, I can proceed with execution
-> Require authentication : I get a 401 error before accessing to my function even though the Authorization header is present in the request.

Logs in Function says : The request was not authorized to invoke this service. Read more at https://cloud.google.com/run/docs/securing/authenticating Additional troubleshooting documentation can be found at: https://cloud.google.com/run/docs/troubleshooting#401

I went on these docs but couln't find anything relevant, or that I could understand/apply to my issue.

Am I missing a configuration or a comprehension of 'Require Authentication', I thought it would check the JWT before my function executes so I wouldn't have to do it in the function.

Thanks and have a lovely day,

0 1 2,221
1 REPLY 1

Hi @Xolkys,

Welcome to Google Cloud Community!

 

To authenticate Firebase users on Google Functions, you need to:

  1. Ensure that your React Native app is sending a valid OAuth 2.0 bearer token in the Authorization header of all requests to your function.
  2. Set the function's HTTPS trigger to Allow unauthenticated invocations.
  3. Use the correct Authorization header format: Bearer <token>, where <token> is the OAuth 2.0 bearer token.
  4. Make sure that the token you are sending has not expired.

Reference that might be helpful:

Top Solution Authors