首页 > 解决方案 > Firebase Authentification and Flask

问题描述

I am trying Firebase to authenticate users for a website that was initially built on Flask (using the flask login workflow with a postgres DB). However, I am not sure that I have a correct understanding of what would be considered best practices when using Firebase.

I read through this article, which I think has led me down a suboptimal path when it comes to actually managing users.

My questions are:

  1. Should all the Firebase authentication be handled in the javascript?
  2. If so, should I use the request.headers on the backend to verify the identity of the user?

Any tutorials (aside from the Firenotes one, which I am working through) much appreciated.

标签: firebaseflaskfirebase-authentication

解决方案


是否应该在 javascript 中处理所有 Firebase 身份验证?

不,它不一定是 JavaScript。但总的来说,您会发现大多数使用现有 Firebase 身份验证提供程序之一的应用程序在其客户端代码中处理用户登录,并调用身份验证服务器。

如果是这样,我应该使用后端的 request.headers 来验证用户的身份吗?

在调用 REST API 时,Firebase 本身会在Authorization标头中传递经过身份验证的用户的 ID 令牌,因此这确实是一种有效的方法。然后,您可以在服务器上验证 ID 令牌是否有效,并决定该用户有权访问哪些数据。


推荐阅读