Django 1.7 google oauth2 token validation failure

后端 未结 2 1187
失恋的感觉
失恋的感觉 2021-02-15 19:40

I\'m trying to get through the process of authenticating a Google token for accessing a user\'s calendar within a Django application. Although I\'ve followed several indications

相关标签:
2条回答
  • 2021-02-15 19:54

    It could be a unicode issue with request.REQUEST['state']. Try putting str() around it, i.e. str(request.REQUEST['state']).

    0 讨论(0)
  • 2021-02-15 19:59

    I have struggled exact the same issue for several hours, and I figured out the solution of which @Ryan Spaulding and @Hans Z answered. It works!

    This is due to the fact Django 1.7 returns a unicode object for the state variable above using request.REQUEST. I was previously using Django 1.6 which used to return a string.

    One can find more detail here. https://github.com/google/google-api-python-client/issues/58 I wrote this post for future reference.

    if not xsrfutil.validate_token(
        settings.SECRET_KEY, 
        str(request.REQUEST['state']), 
        request.user):
    return HttpResponseBadRequest()
    
    0 讨论(0)
提交回复
热议问题