在没有前端的情况下从 firebase auth 模拟器获取用户的未签名令牌

Vri*_*ain 2 firebase firebase-authentication firebase-admin nestjs

我正在编写一个自定义后端(nestjs),其中我想验证来自 firebase auth 的令牌是否有效并检索用户信息。

我不想使用实际的 firebase 身份验证,因此我最终使用了 firebase 本地模拟器。

现在我想使用 postman 测试用 Nestjs 编写的端点,其中我从 postman 发送未签名的令牌以供 Nestjs 从本地模拟器进行验证。但我无法找到一种方法来创建未签名的令牌而不为其创建 UI,我真的不想花时间创建仅针对console.log令牌的反应应用程序。有没有更好的方法来做到这一点,我可能会错过?

谢谢您的帮助。

Dan*_*ñoz 7

假设您的身份验证模拟器在端口上运行9099并且您创建了一个用户,您应该能够发出以下 HTTPPOST请求来获取令牌。令牌位于idToken响应对象的字段中。

http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=any_key_you_want

正文(JSON):

{
  "email": "your-user@mail.com",
  "password": "some-password"   
}
Run Code Online (Sandbox Code Playgroud)

回复:

{
    "kind": "identitytoolkit#VerifyPasswordResponse",
    "registered": true,
    "localId": "yourUserId",
    "email": "your-user@mail.com",
    "idToken": "someIdToken",
    "refreshToken": "someRefreshToken",
    "expiresIn": "3600"
}
Run Code Online (Sandbox Code Playgroud)

我发现这个解决方案使用firebase安装了 (^9.6.2) 包的 React 应用程序进行设置connectAuthEmulator(auth, "http://localhost:9099");,并查看我登录时发出的请求。