请帮助使用Firebase身份验证的最终用户在云中进行身份验证。
简短说明: 我从Firebase函数提交了授权:Bearer + idToken标头,其中idToken已通过电子邮件/密码Firebase用户 user1 进行了身份验证。 我将其提交给为此 user1 设置了Cloud Run Invoker角色的Cloud Run实例。 但是在云运行日志中,我看到以下错误:
该请求未被授权调用此服务。在https://cloud.google.com/run/docs/securing/authenticating
中了解更多信息我在做什么错?如何通过已验证用户调用的firebase函数调用云运行端点调用?
更多详细信息:
我有一个具有电子邮件/密码Firebase身份验证的简单Firebase应用程序。 当 user1 (例如test@test.com)已使用电子邮件/密码进行身份验证时,我使用firebase.User.getIdToken()获取该用户的ID令牌,并将其提交给firebase函数。
在firebase函数端,我提取用户令牌,并将其作为Authorization:Bearer + token header提交给google cloud run端点:
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
在google cloud run上,我已经部署了cloud run端点。 在“云运行权限”选项卡上,我已为 user1 test@test.com设置了“云运行调用者”角色。
但是当我执行上述firebase函数getData时,我在云运行日志中看到以下错误:
2020-10-29 14:30:13.498 MSK GET 401 0 B 0 ms@root+request/1.6.1节点/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身份验证(完成)并手动验证其凭据。 如何手动验证凭据?提交不记名授权令牌后该怎么办?
答案 0 :(得分:2)
要实现这一目标,您有两种解决方案: