如何使用 python flask 从 firebase auth 注销/注销

问题描述

我正在使用 firebase auth 创建一个简单的登录、注销、注册 Flask Web 应用程序,我成功创建了登录注册,但卡在了注销状态。那么有没有办法从firebase auth注销或注销? 谢谢

解决方法

无法使特定令牌无效,但您可以使刷新令牌无效 (refer this article)

但这似乎不是你的问题。因此,解决此问题的最佳方法是删除令牌或从客户端忘记用户:

auth.current_user = None

用户设置为 None 后,请求将不会被验证,因此更像是用户已注销。

不过,如果您想针对某些特定情况实施此操作,您可以refer here

,

当您使用 firebase 登录时,它通常会为您提供一个刷新令牌和一个 id 令牌。这些是识别用户的 JWT,另一个在 id 令牌过期时刷新 id 令牌,因为 id 令牌在 1 小时后过期。

如果您使用的是 PyreBase 之类的东西 auth.current_user = None 不安全。

相反,您应该查看提供的注销方法。

import pyrebase

firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
user = auth.sign_in_with_email_and_password(email,password)
auth.signOut()