-
Notifications
You must be signed in to change notification settings - Fork 37
Switch to pure ADAL #94
Conversation
c1896a7
to
083a544
Compare
45670fa
to
35ae5aa
Compare
@yugangw-msft It's done, testing is ok, I'd appreciate if you can take a look :) I didn't tested SDK yet, doing it right now. |
ChangeLog: Breaking changes These breaking changes applies to ServicePrincipalCredentials, UserPassCredentials, AADTokenCredentials
Features
|
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.
Please test it with real credentials. If works, then all good.
# Beware that ADAL returns a pointer to its own dict, do | ||
# NOT change it in place | ||
token = token.copy() | ||
|
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 think, I'm running into this bug with the following code. Can this change be hotfixed on the latest release? It appears this PR may take some time.
AUTHORITY_URL = "https://login.microsoftonline.com" + '/' + os.environ["TENANT"]
auth_context = adal.AuthenticationContext(AUTHORITY_URL, api_version=None)
resource = "https://vault.azure.net"
client_id = os.environ["CLIENT_ID"]
client_secret = os.environ["CLIENT_SECRET"]
token = auth_context.acquire_token_with_client_credentials(resource, client_id, client_secret)
credentials = AADTokenCredentials(token, client_id)
print("Got one token. Trying to get the token again")
token = auth_context.acquire_token_with_client_credentials(resource, client_id, client_secret)
credentials = AADTokenCredentials(token, client_id)
print("Got one token second time as well")
The second print never gets printed and I get this exception.
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 76, in __init__
'{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not float
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.
Hi @prburgu
Sounds plausible, but could I get the complete stacktrace please? Not just the last line.
Also, this PR will be merged as 0.5.0, but this creates some conflicts right now with some packages that requires 0.4.x. I hope all will be merged and released by this summer.
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.
Actually, I've worked around this issue in my code, so there is no urgent need for hotfix and I'll leave it up to you on that. Here is the complete stacktrace.
Traceback (most recent call last):
File "adal_test.py", line 13, in <module>
token = auth_context.acquire_token_with_client_credentials(resource, client_id, client_secret)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/adal/authentication_context.py", line 179, in acquire_token_with_client_credentials
return self._acquire_token(token_func)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/adal/authentication_context.py", line 128, in _acquire_token
return token_func(self)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/adal/authentication_context.py", line 177, in token_func
return token_request.get_token_with_client_credentials(client_secret)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/adal/token_request.py", line 306, in get_token_with_client_credentials
token = self._find_token_from_cache()
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/adal/token_request.py", line 128, in _find_token_from_cache
return self._cache_driver.find(cache_query)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/adal/cache_driver.py", line 201, in find
is_resource_tenant_specific)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/adal/cache_driver.py", line 167, in _refresh_entry_if_necessary
expiry_date = parser.parse(entry[TokenResponseFields.EXPIRES_ON])
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 1356, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 645, in parse
res, skipped_tokens = self._parse(timestr, **kwargs)
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 721, in _parse
l = _timelex.split(timestr) # Splits the timestr into tokens
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 207, in split
return list(cls(s))
File "/Users/prburgu/Downloads/test1/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 76, in __init__
'{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not float
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 was looking for the _find_token_from_cache
and it's there :). You're right, that's the correct fix.
I'd rather wait for this PR to be merged if it's ok for you.
Merging in the 0.6.0 branch |
For some reason I called the branch 0.6.0 and 0.5.0.... I renamed the branch. |
* Switch to pure ADAL (#94) * Switch to pure ADAL * ADAL 0.6.0 and some tests * Full ADAL testing * Bring back china=True since easy to support * Restore set token on __init__ behavior * Typo * Adding back attribute as property * Clarify AADTokenCredentials doc * Add AzureStack support to credentials * Fix doc * Add cache support * Current 0.5.0 and ChangeLog * Remove keyring (#112) * Remove keyring * keyring changelog * Deserialize addtionalInfo in ARM error (#102) * ChangeLog * Docstring cleanup
Switch to ADAL implementation. Will require a msrestazure 0.5.0, since there is some internal changes that I can't assume no one is using.
Deprecate at the same time some old stuff, like
china=True
Needs AzureAD/azure-activedirectory-library-for-python#142 to be iso-functional
Edit: Since adal 0.6.0 I have everything I need to migrate in a iso-functional way