【发布时间】:2021-02-11 21:34:53
【问题描述】:
请帮助最终用户使用 Firebase 身份验证在云运行中进行身份验证。
简短说明: 我提交 Authorization: Bearer + idToken header from firebase function with idToken of authenticated with email/password firebase user user1。 我将它提交到云运行实例,并为此 user1 设置了 Cloud Run Invoker 角色。 但在云运行日志中,我看到以下错误:
请求未被授权调用此服务。阅读更多https://cloud.google.com/run/docs/securing/authenticating
我做错了什么?如何从经过身份验证的用户调用的 firebase 函数调用云运行端点调用?
更多细节:
我有一个带有电子邮件/密码 firebase 身份验证的简单 firebase 应用。 当 user1 说 test@test.com 使用电子邮件/密码进行身份验证时,我使用 firebase.User.getIdToken() 为该用户获取 Id 令牌并将其提交给 firebase 函数。
在firebase功能方面,我提取用户令牌并将其作为授权提交到谷歌云运行端点:承载+令牌头:
export const getData = functions.https.onRequest(
async (req, response) => {
cors(req, response, async () => {
getToken(req)
.then(async (token: any) => {
const options = {
url: cloud_run.CLOUD_RUN_ENDPOINT,
headers: {
Authorization: `Bearer ${token}`,
},
};
request.get(options, async function (err, resp) {
//Processing the result
});
//etc
在谷歌云运行中,我已经部署了云运行端点。 在云运行权限选项卡上,我为我的 user1 test@test.com 设置了 Cloud Run Invoker 角色。
但是当我执行上述的firebase函数getData时,我在云运行日志中看到以下错误:
2020-10-29 14:30:13.498 MSK GET 401 0 B 0 ms@root+request/1.6.1 node/v10.22.0 linux/4.4.0 Linux/x64 https://
该请求未被授权调用此服务。阅读更多https://cloud.google.com/run/docs/securing/authenticating
根据本手册: https://cloud.google.com/run/docs/authenticating/end-users 为 firebase 身份验证:https://cloud.google.com/run/docs/authenticating/end-users#cicp-firebase-auth
我需要实施 Identity Platform 或 Firebase 身份验证(已完成)并手动验证其凭据。 如何手动验证凭据?提交不记名授权令牌后该怎么办?
【问题讨论】:
-
您不能使用 Firebase 身份验证凭据来验证对受 Google Cloud IAM 保护的 Cloud Run 的请求。您必须提供 IAM 可识别的身份,这通常意味着服务帐户。如果您想使用 Firebase 身份验证,则必须允许任何人调用端点,并在后端代码中使用 Firebase Admin SDK 检查身份验证凭据。
标签: node.js firebase authentication firebase-authentication google-cloud-run