-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Core} Fix the incorrect token expiration on ADAL tokens #15875
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
Changes from all commits
e11fea0
3df3592
a7d9cf0
03d466c
0f28a7c
2bb621c
175f819
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import datetime | ||
| import time | ||
| import requests | ||
| import adal | ||
|
|
@@ -75,6 +76,13 @@ def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument | |
| logger.debug("AdalAuthentication.get_token invoked by Track 2 SDK with scopes=%s", scopes) | ||
|
|
||
| _, token, full_token, _ = self._get_token(_try_scopes_to_resource(scopes)) | ||
|
|
||
| try: | ||
| expires_on = full_token.get('expiresOn', full_token['expires_on']) | ||
| return AccessToken(token, int(datetime.datetime.strptime(expires_on, '%Y-%m-%d %H:%M:%S.%f').timestamp())) | ||
| except: # pylint: disable=bare-except | ||
| pass # To avoid crashes due to some unexpected token formats | ||
|
|
||
| try: | ||
| return AccessToken(token, int(full_token['expiresIn'] + time.time())) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still we need to figure out why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jiasli From my understanding, relative values like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code is really "carving the boat to seek the sunk sword" (刻舟求剑). |
||
| except KeyError: # needed to deal with differing unserialized MSI token payload | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
For a user token (which has
expiresOn),full_token['expires_on']will be evaluated first and result in aKeyError.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.
This will also break Cloud Shell because
expires_onis an epoch time and should be used directly. Parsing it will result in failure.