Use http Google Cloud Functions "Require Authentication" with Firebase - Stack Overflow

In my front-end, I'm using the Firebase authentication and the firebaseAuth.currentUser?.getIdToke

In my front-end, I'm using the Firebase authentication and the firebaseAuth.currentUser?.getIdToken(true) function to get the token and send it as an Authorization: Bearer {token} header to the Google function.

I used to parse the token in the function and validate it within the function code. But I want to enable the Require authentication setting for it. The problem is that I receive the Your client does not have permission to the requested URL error in this case.

I tried to set the allAuthenticatedUsers, {project}@appspot.gserviceaccount and firebase-service-account@firebase-sa-management.iam.gserviceaccount principals with Cloud Functions Invoker role, but it did not help.

Is there any way I can do so Require Authentication is enabled, and GC allows to execute the function only for the users authenticated with the Firebase?

In my front-end, I'm using the Firebase authentication and the firebaseAuth.currentUser?.getIdToken(true) function to get the token and send it as an Authorization: Bearer {token} header to the Google function.

I used to parse the token in the function and validate it within the function code. But I want to enable the Require authentication setting for it. The problem is that I receive the Your client does not have permission to the requested URL error in this case.

I tried to set the allAuthenticatedUsers, {project}@appspot.gserviceaccount and firebase-service-account@firebase-sa-management.iam.gserviceaccount principals with Cloud Functions Invoker role, but it did not help.

Is there any way I can do so Require Authentication is enabled, and GC allows to execute the function only for the users authenticated with the Firebase?

Share Improve this question asked Nov 19, 2024 at 10:12 domanskyidomanskyi 7531 gold badge9 silver badges21 bronze badges 1
  • I doubt that the tokens you generate with firebase are compatible with what cloud functions expect, see cloud.google/functions/docs/securing/… and compare it with firebase.google/docs/auth/admin/verify-id-tokens The audience and sub fields have a completely different content. – somethingsomething Commented Nov 19, 2024 at 14:48
Add a comment  | 

1 Answer 1

Reset to default 2

Google Cloud IAM roles, such as "allAuthenticatedUsers" and service accounts, have nothing at all to do with Firebase Authentication user ID tokens. They aren't compatible with each other and are not interchangeable in any way. You can't simply replace your code to validate a Firebase Auth token with IAM permissions.

The only way to implement Firebase Auth token validation is using code you write, typically with the Firebase Admin SDK.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745568738a4633551.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信