我正在尝试为我的 Cloud Run 托管容器设置 GCP Api 网关,但我收到了一些关于 Firebase 身份验证的错误。
在 api 规范中,我复制了 api gateway guide 中发布的内容
firebase:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "https://securetoken.google.com/{{ project_id }}"
x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
x-google-audiences: "{{ project_id }}"
并在端点路径中添加了安全条目
security:
- firebase: []
当我通过 Api Gateway 发出请求时,一些额外的标头会添加到代理到 Cloud Run 服务的请求中,例如x-apigateway-api-userinfo
,x-forwarded-authorization
和authorization
然后,在 Cloud Run 服务中,我必须使用 Firebase Admin sdk 来验证通过的令牌并识别发出请求的用户。这就是问题开始的地方,当我尝试验证此标头的任何令牌时,我收到一个错误:“FirebaseAuthError:解码 Firebase ID 令牌失败。确保您传递了代表 ID 令牌的整个字符串 JWT。”
我做错什么了吗?如何解码传递给 Api 网关的身份验证令牌?