简体   繁体   English

如何使用Firebase JWT在自定义后端上对用户进行身份验证?

[英]How do I authenticate my user on a custom backend using my firebase JWT?

I successfully authenticated my user with my firebase app in the browser. 我在浏览器中使用Firebase应用成功验证了用户身份。 Now I want my custom backend to know that the user is authenticated. 现在,我希望自定义后端知道用户已通过身份验证。

How do I go about this? 我该怎么办? Can I tell the client to include the firebase JWT in every request to my backend, so that the backend knows the user is logged in? 我可以告诉客户端在对后端的每个请求中都包含Firebase JWT,以便后端知道用户已登录吗? (This is necessary so that the backend will not redirect a logged-in user to the login page, for example.) (这是必要的,以便后端不会将已登录的用户重定向到登录页面。)

Background Research: 背景研究:

The firebase authentication docs explain how to get the firebase token, send it to your custom backend, and then do something on the backend with the user data. Firebase身份验证文档介绍了如何获取Firebase令牌,将其发送到您的自定义后端,然后在后端使用用户数据执行某些操作。 That's fine for an XHR request, where you can tell the browser to include the token as a header. 对于XHR请求,这很好,您可以在其中告诉浏览器将令牌包括为标头。 I don't understand how to get the browser to include the token in a normal HTTP request to the server, like when the user opens a new tab and navigates to the admin panel at https://example.com/admin . 我不明白如何让浏览器将令牌包含在对服务器的常规HTTP请求中,例如当用户打开新标签并导航至https://example.com/admin的管理面板时。

This is a related question , but I didn't understand the answer (or at least how I could apply it to my use case). 这是一个相关的问题 ,但是我不明白答案(或者至少不知道如何将其应用于用例)。

Here's how the good guys at jwt.io explain it: 这是jwt.io的好人如何解释它:

Whenever the user wants to access a protected route or resource, the user agent should send the JWT, typically in the Authorization header using the Bearer schema. 每当用户想要访问受保护的路由或资源时,用户代理通常应在Bearer模式中使用授权头发送JWT。 The content of the header should look like the following: 标头的内容应如下所示:

Authorization: Bearer <token> 授权:不记名<token>

This is a stateless authentication mechanism as the user state is never saved in server memory. 这是一种无状态的身份验证机制,因为用户状态永远不会保存在服务器内存中。 The server's protected routes will check for a valid JWT in the Authorization header, and if it's present, the user will be allowed to access protected resources. 服务器的受保护路由将在Authorization标头中检查有效的JWT,如果存在,则将允许用户访问受保护的资源。

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

相关问题 如何公开我的自定义 xampp 域名? - How do I make my custom xampp domain name public? 如何对我后端的API进行REST API调用 - How to make REST APIs calls for APIs I have on my Backend 如何使用MSXML2.XMLHTTP和VBA进行身份验证? - How do I authenticate using MSXML2.XMLHTTP and VBA? 如何检查此用户是匿名用户还是我系统上的实际用户? - How do I check whether this user is anonymous or actually a user on my system? 如何验证我的所有 (JavaScript) AJAX 请求? (发送到 Node.js) - How can I authenticate all of my (JavaScript) AJAX requests? (sending to Node.js) 如何通过我的Android应用程序为网络服务验证用户身份? - How can I authenticate users via my android app for a web service? 我应该在哪里托管我的Android应用程序的php后端? - Where should I host my php backend for my Android App? 如何从RESTANGULAR HTTP请求中删除这些自定义查询参数? - How do I remove these custom query parameters from my RESTANGULAR HTTP Request? 如何以编程方式配置我的Jetty请求处理程序以处理自定义HTTP方法 - How do I programatically configure my Jetty Request Handler to Handle custom HTTP methods 如何使用 CURL 或其他 HTTP REST 客户端验证 JHipster 单体 Web 应用程序(JWT 令牌)以使用服务 - How to authenticate JHipster monolithic web applications (JWT tokens) to consuming services using CURL or other HTTP REST client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM