Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth Token does not validate with unicode state variable #58

Closed
qcaron opened this issue Feb 26, 2015 · 2 comments
Closed

OAuth Token does not validate with unicode state variable #58

qcaron opened this issue Feb 26, 2015 · 2 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@qcaron
Copy link

qcaron commented Feb 26, 2015

Hi guys,

I had a problem to validate the oauth2 token with xsrfutil.validate_token.
Indeed, I switched to Django 1.7 which gives a unicode object when getting the state parameter of the oauth callback URL.

The initial state variable passed to Google is built as following:

flow.flow.params['state'] = xsrfutil.generate_token(google_app.secret,
                                                    request.user, 
                                                    action_id=GOOGLE_API_ACCESS_ACTION_ID)
...
return HttpResponseRedirect(flow.flow.step1_get_authorize_url())

Then I try to validate the token using xsrfutil.validate_token in my oauth return view as follows:

if not xsrfutil.validate_token(google_app.secret,
                               state,
                               request.user,
                               action_id=AUTHORIZE_GOOGLE_API_ACCESS_ACTION_ID):
            return HttpResponseBadRequest('Your Google API token could not be validated.')

with:

state = request.REQUEST['state']

However, I had to use

state = str(request.REQUEST['state'])

so the token validates.

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.

I believe this is somehow related to the api's Python 3 migration enhancement, which is not available yet. It would be nice to update the api documentation and django samples to reflect this issue.

@ghost ghost mentioned this issue Dec 16, 2015
@bantini
Copy link
Contributor

bantini commented Feb 1, 2018

Is anyone still facing this problem with the latest version of the library?

@bantini
Copy link
Contributor

bantini commented Feb 14, 2018

Closing this for now, assuming the latest version solves this. You can reopen this issue if the problem comes up.

@bantini bantini closed this as completed Feb 14, 2018
akrherz pushed a commit to akrherz/google-api-python-client that referenced this issue Apr 1, 2019
multistore_file.py: don't write trailing whitespace in json creds
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants