django - 如何使用 django python 从 firebase 注销
问题描述
我正在尝试使用 python 和 firebase 从后端创建用户身份验证。到目前为止,创建用户和登录操作效果很好。但不知何故,我找不到任何有关 signOut 操作的信息。我正在使用 Pyrebase 库。有人有建议吗?这是它起作用的部分:
import pyrebase
config = {
#my private config informations
}
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
def createAccount(request):
if request.method == "POST":
email=request.POST.get("email")
password = request.POST.get("password")
auth.create_user_with_email_and_password(email, password)
return render(request, 'beforeLogin/landingPage.html')
def verifyLogin(request):
if request.method == 'POST':
email=request.POST.get("email")
password = request.POST.get("password")
try:
auth.sign_in_with_email_and_password(email, password)
except:
messages.error(request,'Email or password is not correct.')
return render(request, 'beforeLogin/landingPage.html')
return redirect(settings.LOGIN_REDIRECT_URL)
return HttpResponse("why y r here")
如果您有更好的选择,我可以更改我的图书馆。提前致谢。
解决方案
根据Pyrebase 源代码中的这一行,正在返回一个安全令牌。
data = json.dumps({"email": email, "password": password, "returnSecureToken": True})
大多数令牌是无状态的,这意味着服务器不存储任何类型的会话。当 Pyrebase 向服务器发出请求时,它会在每个请求的标头中发送令牌。只要该令牌存在、有效且未过期,服务器就会认为它已通过身份验证。
此令牌与其他一些用户数据一起存储在auth.current_user
. 要注销用户,只需将 设置current_user
为None
。
auth.current_user = None
没有令牌,请求将不再被验证。
推荐阅读
- ios - 使用 appstore 验证应用程序时出现代码登录问题
- django - 无法在 Django 网站上转发或跳过视频
- rest - 如何正确使用 REST API 上传 Salesforce 文件?
- python - Python Tkinter 按钮冻结解决方案?
- java - Cucumber/Gherkin 测试被 TestNG 忽略但适用于 JUnit
- tomcat - HTTP 请求/响应:端口 80 到端口 8085
- javascript - React 导入语句的标准方式
- java - 定义 jboss-web.xml 安全域会导致我的 EJB 缺少依赖项
- python - 如何从python中的字节数组中获取位?
- sql - 最近两个月的记录和他们在oracle中的差异