我正在使用新的 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 和客户端密钥?如果它们是我应该使用的。
我知道我需要某种授权标头来进行删除调用,但我只是不知道应该在该标头中放置什么,或者如何放置。
感谢您对此的任何见解。
编辑:我现在已经尝试了以下授权标头:
“管理员”
“”(空字符串)
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]"
}
谢谢!但是,我想将其与curl 格式一起使用以在npm 脚本上获取它,所以这是我使用的:
curl -H 'Authorization: Bearer owner' -X DELETE http://localhost:9099/emulator/v1/projects/<projectid>/accounts
回应应该是:
{}
我想通了!当管理员生成令牌时,我使用该令牌的 access_token 字段部分并将标头
Authorization: 'Bearer' + access_token
添加到删除请求中。感谢您的帮助。
(这是仅模拟器端点)
编辑:我可以使用字符串“owner”作为令牌...我花了一段时间才得到它,但现在它可以工作了。
我问了类似的问题如何以管理员身份删除真实用户,我的问题可能被谷歌员工关闭了。他们如何让人们关闭真是令人恶心。