微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Django social-auth:如何处理 Youtube (Google) Auth 错误:AuthStateForbidden?

如何解决Django social-auth:如何处理 Youtube (Google) Auth 错误:AuthStateForbidden?

我在 Google Analytics 和 Youtube 中使用 django social-auth 授权用户。因此使用了 2 个不同模板中的一个后端。然而,使用 Google Analytics 一切正常,但当我在身份验证过程结束时尝试在 Youtube 中授权时出现错误

social_core.exceptions.AuthStateForbidden:给出了错误的状态参数。

我已尝试从 Google 帐户中删除已成功授权我的 Google Analytics Scopes 应用程序,并再次为 Youtube Scopes 授权,但没有任何区别。

我的 YouTube 处理程序:

class YouTubeLoginHandler(object):
    def __init__(self,client_secret):
        self.ScopES = ['https://www.googleapis.com/auth/youtube.readonly']
        self.CLIENT_SECRETS_PATH = client_secret

    def init_youtube_api(self):
        flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
            os.path.abspath(
                os.path.join(os.path.dirname(__file__),self.CLIENT_SECRETS_PATH)
            ),scopes=self.ScopES)


        flow.redirect_uri = 'http://localhost:8000/apI/Oauth/complete/google-oauth2/'

        authorization_url,state = flow.authorization_url(
            # Enable offline access so that you can refresh an access token without
            # re-prompting the user for permission. Recommended for web server apps.
            access_type='offline',# Enable incremental authorization. Recommended as a best practice.
            include_granted_scopes='true')

        return authorization_url

我在 views.py 中的视图

@login_required
def login_youtube(request):
    user = request.user
    youtube = YouTubeLoginHandler('client_secrets.json')
    authorization_url = youtube.init_youtube_api()
    return HttpResponseRedirect(authorization_url)
   

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。