【问题标题】:Python-Social-Auth shows 'AuthStateForbidden' sometimesPython-Social-Auth 有时会显示“AuthStateForbidden”
【发布时间】:2015-07-31 19:14:37
【问题描述】:

有时当我尝试登录或注册 Facebook 或 Google 时,它​​会返回错误 AuthStateForbidden 屏幕

但是只要刷新页面或者过一会再试,就可以正常运行了。

我尝试在 Google 开发人员中添加 Google+ API,但在 Facebook 中出现同样的问题。

有什么想法吗?

提前致谢!

【问题讨论】:

    标签: python django python-social-auth


    【解决方案1】:

    我也多次遇到这个问题。从文档中我们知道:

    AuthStateForbidden - 服务器返回的状态参数 不是 发送的那个

    class AuthStateForbidden(AuthException):
        """State parameter is incorrect."""
        def __str__(self):
            return 'Wrong state parameter given.'
    

    我已经搜索了任何类型的解决方案或解决方法,但都没有结果。我也试图以某种方式捕获这个异常,但这是一个棘手的错误。我不知道如何重现它。

    正如我所说,我已经在 python-social-auth 的错误跟踪器中搜索了 AuthStateForbidden 的任何存在 - 没有。此外,目前还有50多个未解决的问题。无论如何,可以创建一个new one

    引发此错误here

    def validate_state(self):
        """Validate state value. Raises exception on error, returns state
        value if valid."""
        if not self.STATE_PARAMETER and not self.REDIRECT_STATE:
            return None
        state = self.get_session_state()
        request_state = self.get_request_state()
        if not request_state:
            raise AuthMissingParameter(self, 'state')
        elif not state:
            raise AuthStateMissing(self, 'state')
        elif not request_state == state:
            raise AuthStateForbidden(self)
    

    here (facebook.py) 调用:

    @handle_http_errors
    def auth_complete(self, *args, **kwargs):
        """Completes loging process, must return user instance"""
        self.process_error(self.data)
        if not self.data.get('code'):
            raise AuthMissingParameter(self, 'code')
        state = self.validate_state()
    

    并且状态是在OAuthAuth中创建的,它实现了BaseAuth并且是BaseOAuth的父级,这是FacebookOAuth的父级等等......几乎不可能遵循这段代码。

    我希望,guthub 问题将来能解决问题。

    【讨论】:

    • 感谢您的回复和您的时间,我还在那里创建了一个issue(但关于其他主题)。我还没有做任何事情来解决这个问题,但我还没有再看到它。但我意识到避免错误屏幕的一种方法是编写基于SocialAuthExceptionMiddlewaremiddleware 并捕获异常。无论如何,我希望这个谜团尽快得到解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 2015-01-05
    • 2014-01-21
    • 2014-08-17
    • 2017-02-28
    • 2017-05-05
    相关资源
    最近更新 更多