[英]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.