简体   繁体   English

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

[英]Get unsigned token for user from firebase auth emulator without frontend

I am writing a custom backend (nestjs) in which I want to verify if the token from firebase auth is valid and retrieve user information too.我正在编写一个自定义后端(nestjs),我想在其中验证来自 firebase 身份验证的令牌是否有效并检索用户信息。

I do not want to use the actual firebase auth so I ended up using firebase local emulator.我不想使用实际的 firebase 身份验证,所以我最终使用了 firebase 本地仿真器。

Now I want to test my endpoint written in nestjs using postman wherein I send the unsigned token from postman for nestjs to verify from local emulator.现在我想使用 postman 测试我用 nestjs 编写的端点,其中我从 postman 发送未签名的令牌,供 nestjs 从本地模拟器进行验证。 But I couldn't find a way to create an unsigned token without creating a UI for the same, I really do not want to spend time in creating a react application to just console.log a token.但是我找不到一种方法来创建一个未签名的令牌而不创建一个 UI,我真的不想花时间创建一个反应应用程序来console.log一个令牌。 Is there any better way to do this that I might be missing??有没有更好的方法来做到这一点,我可能会错过?

Thanks for the help.谢谢您的帮助。

Assuming your Authentication emulator runs on port 9099 and you have a user created, you should be able to make the following HTTP POST request to get a token.假设您的身份验证模拟器在端口9099上运行并且您创建了一个用户,您应该能够发出以下 HTTP POST请求来获取令牌。 The token is in the idToken field of the response object.令牌位于响应 object 的idToken字段中。

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

Body (JSON):正文(JSON):

{
  "email": "your-user@mail.com",
  "password": "some-password"   
}

Response:回复:

{
    "kind": "identitytoolkit#VerifyPasswordResponse",
    "registered": true,
    "localId": "gJGl9qliaf3tk4r83vjGkTUU0GYd",
    "email": "your-user@mail.com",
    "idToken": "someIdToken",
    "refreshToken": "someRefreshToken",
    "expiresIn": "3600"
}

I found this solution playing with a React application with the firebase (^9.6.2) package installed, setting connectAuthEmulator(auth, "http://localhost:9099");我发现这个解决方案与安装了firebase (^9.6.2) package 的 React 应用程序一起使用,设置connectAuthEmulator(auth, "http://localhost:9099"); , and looking at the request it made when I logged in. ,并查看它在我登录时发出的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Flutter 上的 Firebase Auth 获取用户 ID 令牌更改 - How to get user ID token changes from Firebase Auth on Flutter 从过期的Firebase身份验证令牌获取UID? - Get UID from expired Firebase auth token? Firebase Auth-如何在没有当前用户对象的情况下刷新访问令牌 - Firebase Auth - how to refresh access token without current user object 在Firebase中,如何从自定义jwt令牌身份验证获取当前登录的用户 - In Firebase how to get currently logged in user from from custom jwt token auth 如何在不使用任务监听器的情况下获取Firebase验证令牌? - How to get Firebase Auth Token without using Task Listeners? 使用 Firebase Auth 模拟器以编程方式创建用户 - Create a user programatically using Firebase Auth emulator Flutter Firebase 身份验证 - INVALID_REFRESH_TOKEN(Firebase 模拟器) - Flutter Firebase Auth - INVALID_REFRESH_TOKEN (Firebase Emulator) 无法在模拟器上获取 FIS 身份验证令牌 - Failed to get FIS auth token on emulator Graphcool的Firebase身份验证令牌 - firebase auth token from Graphcool |已解决| 从 Firebase 获取用户身份验证数据并将其添加到 Firebase DB - |SOLVED| Get User Auth data from Firebase & add it to Firebase DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM