-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Samples for migrating from Python 2.7 runtime to Python 3.7 #3656
Conversation
… the Python 3.7 version)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM, a few nits and it looks like lint's failing.
url = request.form['url'] | ||
token = id_token.fetch_id_token(reqs.Request(), url) | ||
|
||
resp = requests.get(url, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better as:
resp = requests.get(
url,
headers={'Authorization': 'Bearer {}'.format(token)}
)
info = id_token.verify_oauth2_token(token, requests.Request()) | ||
service_account_email = info['email'] | ||
incoming_app_id, domain = service_account_email.split('@') | ||
if domain != 'appspot.gserviceaccount.com': # Not App Engine svc acct | ||
return None | ||
else: | ||
return incoming_app_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May also want to verify the audience & issuer here.
The (Python) verify_oauth2_token function verifies the JWT signature, the aud claim, and the exp claim. You must also verify the iss claim and the hd claim (if applicable) by examining the object that verify_oauth2_token returns. If multiple clients access the backend server, also manually verify the aud claim. (ref)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought long and hard about verifying the audience, but eventually decided that I was showing how to migrate from the old X-Appengine-Inbound-Appid approach, which did not perform that check.
The Google verify_oauth2_token verifies tokens issued by Google's OAuth2 server, so I don't think there needs to a separate check of the issuer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM.
The text & samples on their website for other languages vs. Python are a little misleading. I will file a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that those other language libraries don't do the same issuer
verification automatically.
@engelke Hold on, I thought the text implied that Python doesn't verify issuer automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments.
It's been a while from the last activity. Please rebase to the master when you push your next commit. Also I'll close this PR on Fri June 5th. Feel free to reopen with rebasing. |
Issues were addressed in comments.
…samples into msprint
Replacing use of Python 2.7 runtime-only libraries for storage and web requests.