【问题标题】:How to logout / signout from firebase auth with python flask如何使用python烧瓶从firebase auth注销/注销
【发布时间】:2021-07-30 12:38:18
【问题描述】:

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

【问题讨论】:

    标签: python firebase flask firebase-authentication logout


    【解决方案1】:

    当您使用 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()
    

    【讨论】:

    • 我试过像你说的 auth.signOut() 但它给了我一个属性错误“Auth object has no attribute signOut”
    【解决方案2】:

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

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

    auth.current_user = None
    

    用户设置为无后,请求将不会被认证,因此更像是用户退出了。

    不过,如果您想针对某些特定情况实施此操作,您可以使用一种解决方法refer here

    【讨论】:

    • @ParthNath 太棒了!然后您可以将答案标记为已接受。
    猜你喜欢
    • 1970-01-01
    • 2017-11-09
    • 2017-02-28
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 2017-12-31
    • 2018-05-20
    • 2017-04-15
    相关资源
    最近更新 更多