【发布时间】:2021-02-26 21:53:06
【问题描述】:
我正在使用新的 firebase auth 模拟器(在节点管理 SDK 上),如果我在每次测试之间手动删除创建的用户,我已经做了一些可以完美运行的测试,但我似乎无法自动删除他们?
我使用了在 beforeEach() 中定义的端点 here,但我从响应调用中得到了“响应代码 401,未经授权”?
端点:删除:http://localhost:9099/emulator/v1/projects/{project-id}/accounts
我刚刚尝试使用 Postman 发送呼叫,它的响应如下:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
错误中的 URL 似乎除了向网络应用程序添加一个 google 按钮之外没有给我太多帮助,这使我需要创建一个 OAuth2 网络帐户。我将 localhost:9099 输入到现有的,但不知道应该在哪里使用客户端 ID 和客户端密码?如果它们是我应该使用的。
我知道删除调用需要某种 Authorization 标头,但我只是不知道应该在该标头中放入什么或如何放入。
感谢您对此的任何见解。
编辑:我现在尝试了以下授权标头:
“管理员”
“”(一个空字符串)
firebase.options.credential.getAccessToken() 生成的完整令牌
上述token的access_token字段
上述token的id_token字段。
令牌本身看起来像这样(编辑了一些字段):
{
"access_token":
"[access token string here]",
"expires_in": 3599,
"scope":
"openid https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/cloudplatformprojects.readonly",
"token_type": "Bearer",
"id_token":
"[id token string here]"
}
【问题讨论】:
-
尝试在您的请求中发送
Authorization: Bearer owner标头。但是,我怀疑您是否能够通过在/accounts端点上发出DELETE请求来删除所有用户。至少,prod Firebase Auth 服务不是这样工作的。 -
据我从文档中可以看出,模拟器有这个端点。今天晚些时候我会试试这个,谢谢。
-
端点确实存在,但
DELETE /accounts不会删除所有帐户。 -
这可能只在模拟器中支持。据我所知,生产 API 不支持它。这就是
POST /accounts:batchDeleteAPI 存在于 prod API 中的原因。 -
Emulator 接受
Bearer owner作为 Authorization 标头。你试过吗?
标签: firebase firebase-authentication firebase-admin