如何验证最终用户身份验证令牌(使用 Firebase 身份验证)以调用 google 云 运行 端点?
How to verify end user authenticated token (Firebase auth used) to invoke google cloud run endpoint?
请帮助使用 firebase 身份验证在云 运行 中对最终用户进行身份验证。
简短说明:
我提交授权:来自 firebase 函数的 Bearer + idToken header,idToken 已通过 email/password firebase 用户 user1 进行身份验证。
我将它提交给云 运行 实例,并为此 user1 设置了云 运行 调用者角色。
但是在云 运行 日志中,我看到以下错误:
该请求未被授权调用此服务。在 https://cloud.google.com/run/docs/securing/authenticating
阅读更多内容
我做错了什么?如何从经过身份验证的用户调用的 firebase 函数调用云 运行 端点调用?
更多详情:
我有一个带有 email/password firebase 身份验证的简单 firebase 应用程序。
当 user1,说 test@test.com 使用 email/password 进行身份验证时,我使用 firebase.User.getIdToken() 为该用户获取 Id 令牌并将其提交给firebase 函数。
在 firebase 函数端,我提取用户令牌并将其作为授权提交到 google 云 运行 端点:承载 + 令牌 header:
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 云 运行 上,我部署了云 运行 端点。
在云 运行 权限选项卡上,我为我的 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 node/v10.22.0 linux/4.4.0 Linux/x64 https://<cloud_run.CLOUD_RUN_ENDPOINT>
The request was not authorized to invoke this service. Read more at 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
我需要实施身份平台或 Firebase 身份验证(完成)并手动验证其凭据。
如何手动验证凭据?提交bearer authorization token后怎么办?
为此,您有 2 个解决方案:
- 自行检查未验证云 运行 服务中的令牌。有一个最近很棒的Google Cloud post on this。我个人不喜欢这种解决方案,因为如果发生攻击,则由您的服务来管理如此高的流量,而您要为此付出代价!
- 使用代理。 (旧的)Cloud Endpoint 可以实现这一点,而我 wrote an article on this 1 year ago (with API Keys security definition, but change it with Firebase Auth security definition and use it!). It's quite old because a fresh new service has been release this summer, named API Gateway 今天是完全由 Google 管理的 Cloud Endpoint(今天的功能是一样的,但是 API Gateway 会进化; 不确定 Cloud Endpoint!)
请帮助使用 firebase 身份验证在云 运行 中对最终用户进行身份验证。
简短说明: 我提交授权:来自 firebase 函数的 Bearer + idToken header,idToken 已通过 email/password firebase 用户 user1 进行身份验证。 我将它提交给云 运行 实例,并为此 user1 设置了云 运行 调用者角色。 但是在云 运行 日志中,我看到以下错误:
该请求未被授权调用此服务。在 https://cloud.google.com/run/docs/securing/authenticating
阅读更多内容我做错了什么?如何从经过身份验证的用户调用的 firebase 函数调用云 运行 端点调用?
更多详情:
我有一个带有 email/password firebase 身份验证的简单 firebase 应用程序。 当 user1,说 test@test.com 使用 email/password 进行身份验证时,我使用 firebase.User.getIdToken() 为该用户获取 Id 令牌并将其提交给firebase 函数。
在 firebase 函数端,我提取用户令牌并将其作为授权提交到 google 云 运行 端点:承载 + 令牌 header:
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 云 运行 上,我部署了云 运行 端点。 在云 运行 权限选项卡上,我为我的 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 node/v10.22.0 linux/4.4.0 Linux/x64 https://<cloud_run.CLOUD_RUN_ENDPOINT> The request was not authorized to invoke this service. Read more at 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
我需要实施身份平台或 Firebase 身份验证(完成)并手动验证其凭据。 如何手动验证凭据?提交bearer authorization token后怎么办?
为此,您有 2 个解决方案:
- 自行检查未验证云 运行 服务中的令牌。有一个最近很棒的Google Cloud post on this。我个人不喜欢这种解决方案,因为如果发生攻击,则由您的服务来管理如此高的流量,而您要为此付出代价!
- 使用代理。 (旧的)Cloud Endpoint 可以实现这一点,而我 wrote an article on this 1 year ago (with API Keys security definition, but change it with Firebase Auth security definition and use it!). It's quite old because a fresh new service has been release this summer, named API Gateway 今天是完全由 Google 管理的 Cloud Endpoint(今天的功能是一样的,但是 API Gateway 会进化; 不确定 Cloud Endpoint!)