如何使用Django Python从Firebase注销 [英] how to signout from firebase using django python

查看:64
本文介绍了如何使用Django Python从Firebase注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python和firebase从后端创建用户身份验证.到目前为止,创建用户和登录操作非常有效.但是出于某种原因,我找不到任何有关注销操作的信息.我正在使用Pyrebase库.有人有建议吗?这是它起作用的部分:

I am trying to create user authentication from back-end with python and firebase. So far creating a user and login actions worked perfectly. But for somehow i cannot find any information for signOut action. i'm using Pyrebase library. Any one has a suggestion? Here is the part it works:

 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")

如果您有更好的选择,我可以更改我的图书馆.预先感谢.

I can change my library if you have a better options. Thanks in advance.

推荐答案

根据

According to this line in the Pyrebase source, a secure token is being returned.

data = json.dumps({"email": email, "password": password, "returnSecureToken": True})

大多数令牌是无状态的,这意味着服务器不存储任何类型的会话.当Pyrebase向服务器发出请求时,它将与每个请求一起在标头中发送令牌.只要该令牌存在,有效且尚未过期,服务器就会认为它已通过身份验证.

Most tokens are stateless, meaning the server does not store any sort of session. When Pyrebase is making requests to the server, it's sending the token along in a header with each request. As long as that token is present, valid and hasn't expired, the server will consider it authenticated.

此令牌以及其他一些用户数据存储在 auth.current_user 中.要注销用户,只需将 current_user 设置为 None .

This token, along with some other user data, is stored in auth.current_user. To log a user out, simply set the current_user to None.

auth.current_user = None

没有令牌,将不再对请求进行身份验证.

Without the token, the requests will no longer be authenticated.

这篇关于如何使用Django Python从Firebase注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆