Skip to content

Endpoints JWT authentication BAD_FORMAT under Python3 #1958

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

Closed
wsnel opened this issue Jan 7, 2019 · 1 comment
Closed

Endpoints JWT authentication BAD_FORMAT under Python3 #1958

wsnel opened this issue Jan 7, 2019 · 1 comment
Assignees

Comments

@wsnel
Copy link

wsnel commented Jan 7, 2019

In which file did you encounter the issue?

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/endpoints/getting-started/clients/google-jwt-client.py

Did you change the file? If so, how?

Added .decode('utf-8') in below snippet:

def make_request(host, api_key, signed_jwt):
.
.
.
headers = {
'Authorization': 'Bearer {}'.format(signed_jwt.decode('utf-8'))
}

Describe the issue

When running the example in python3, the string signed_jwt ends up being a 'binary' string. Without the .decode('utf-8'), the Authorization header will not be formatted correctly and will result in a 'BAD_FORMAT' error response.
Consider adding the following comment above the Authorization line:
* "# add .decode('utf-8') to signed_jwt when running under python3"

@daniel-sanche
Copy link
Member

Thanks, I opened a PR to address this here: #2225

I should note the google_id_jwt function will still have Python3 issues as is, since httplib was renamed between versions. But this change adds full compatibility to make_request at least

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants