请帮助使用 firebase 身份验证在云运行中进行最终用户身份验证。
简短的介绍:
我从 firebase 函数提交 Authorization: Bearer + idToken 标头,并使用电子邮件/密码 firebase 用户进行身份验证的 idTokenuser1。
我将其提交到云运行实例,并为此设置了 Cloud Run Invoker 角色user1。
但在云运行日志中我看到以下错误:
该请求未被授权调用此服务。阅读更多内容https://cloud.google.com/run/docs/securing/authenticating https://cloud.google.com/run/docs/securing/authenticating
我究竟做错了什么?如何从经过身份验证的用户调用的 firebase 函数调用云运行端点调用?
更多细节:
我有一个简单的 firebase 应用程序,带有电子邮件/密码 firebase 身份验证。
什么时候user1, say [电子邮件受保护] /cdn-cgi/l/email-protection使用电子邮件/密码进行身份验证,我使用 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
在谷歌云运行上,我部署了云运行端点。
在云运行权限选项卡中,我已为我的云运行调用者角色设置user1 [电子邮件受保护] /cdn-cgi/l/email-protection.
但是当我执行上述 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/securing/authenticating
根据本手册:https://cloud.google.com/run/docs/authentication/end-users https://cloud.google.com/run/docs/authenticating/end-users为了
Firebase 身份验证:https://cloud.google.com/run/docs/authenticating/end-users#cicp-firebase-auth https://cloud.google.com/run/docs/authenticating/end-users#cicp-firebase-auth
我需要实施 Identity Platform 或 Firebase 身份验证(已完成)并手动验证其凭据。
如何手动验证凭据?提交不记名授权令牌后我应该做什么?