# Auth0 JWT having issues with google cloud function

**URL:** <https://community.auth0.com/t/auth0-jwt-having-issues-with-google-cloud-function/123834>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [December 29, 2023, 4:48am UTC](https://community.auth0.com/t/auth0-jwt-having-issues-with-google-cloud-function/123834 "2023-12-29T04:48:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snap-bill](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/snap-bill/32/53555_2.png) [@snap-bill](https://community.auth0.com/u/snap-bill)\
**Post date:** [December 29, 2023, 4:48am UTC](https://community.auth0.com/t/auth0-jwt-having-issues-with-google-cloud-function/123834/1 "2023-12-29T04:48:58Z")

</div>

My project requires HIPAA compliance, so I chose Auth0 as it is HIPAA compliant for authentication.  
The backend is firebase and their auth is not HIPAA compliant, however database and storage are.  
I managed to use Auth0 JWT to create firebase custom tokens then I send back to the client so they login with firebase custom token.  
It is working perfectly on localhost endpoint.

Once, I deploy the endpoint as google cloud function(HTTP triggered function), I am having 401 error, unauthorized.  
This error only happens when I use authenticated user option, however, once I make the function public (Unauthenticated allowed), it works flawlessly.

Here is my question:  
Is the cloud function (API) inherently protected by the fact I am using the middleware  
(express-oauth2-jwt-bearer) to verify the tokens?

code snippet:

 ![Screen Shot 2023-12-28 at 8.44.03 PM](https://global.discourse-cdn.com/auth0/original/3X/5/0/50ac4dabcc8ecdff8a42622d5d07b32f83e3cc4a.png)

If protected then I keep the cloud function url public so everything works fine.

If this is not the best practice, then how to get google cloud to accept my Auth0 JWT to trigger the function?

I did use API gateway Authentication Auth0 protocol based on google documentation, but no luck.  
May be I am missing something.

thank you  
Rabee

---

<div class="post-metadata">

**Author:** ![snap-bill](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/snap-bill/32/53555_2.png) [@snap-bill](https://community.auth0.com/u/snap-bill)\
**Post date:** [January 4, 2024, 5:36am UTC](https://community.auth0.com/t/auth0-jwt-having-issues-with-google-cloud-function/123834/2 "2024-01-04T05:36:13Z")

</div>

I found the answer! 😃

google api gateway will verify Auth0 token for you, then it will forward (x-apigateway-api-userinfo) for your endpoint function/server.  
This header is `base64url` encoded and contains the JWT payload. You have to decode and extract email or userId, sub, sid…etc from it and then one element like an email or sid # can be used to produce a custom token by firebase.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 18, 2024, 5:36am UTC](https://community.auth0.com/t/auth0-jwt-having-issues-with-google-cloud-function/123834/3 "2024-01-18T05:36:35Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
