Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

'NoneType' object has no attribute 'token_type' #29

Closed
Walk4Muscle opened this issue Jun 20, 2016 · 12 comments
Closed

'NoneType' object has no attribute 'token_type' #29

Walk4Muscle opened this issue Jun 20, 2016 · 12 comments

Comments

@Walk4Muscle
Copy link

I am trying to get access token via acquire_token_with_username_password in python 2.7, but I get the following issue:

  File "E:\Projects\python\adal\adal_test.py", line 8, in <module>
    '994e5ec6-28f2-45b3-a892-c9131b266a05')
  File "E:\Projects\python\adal\adal\authentication_context.py", line 125, in acquire_token_with_username_password
    return self._acquire_token(token_func)
  File "E:\Projects\python\adal\adal\authentication_context.py", line 89, in _acquire_token
    return token_func(self)
  File "E:\Projects\python\adal\adal\authentication_context.py", line 123, in token_func
    return token_request.get_token_with_username_password(username, password)
  File "E:\Projects\python\adal\adal\token_request.py", line 265, in get_token_with_username_password
    token = self._get_token_username_password_federated(username, password)
  File "E:\Projects\python\adal\adal\token_request.py", line 243, in _get_token_username_password_federated
    username, password)
  File "E:\Projects\python\adal\adal\token_request.py", line 210, in _perform_username_password_for_access_token_exchange
    return self._perform_wstrust_assertion_oauth_exchange(wstrust_response)
  File "E:\Projects\python\adal\adal\token_request.py", line 182, in _perform_wstrust_assertion_oauth_exchange
    grant_type = _get_saml_grant_type(wstrust_response)
  File "E:\Projects\python\adal\adal\token_request.py", line 55, in _get_saml_grant_type
    token_type = wstrust_response.token_type
AttributeError: 'NoneType' object has no attribute 'token_type'

And my code snippet is like:

import adal
context = adal.AuthenticationContext('https://login.microsoftonline.com/<tenantID>')
RESOURCE = '00000002-0000-0000-c000-000000000000' #AAD graph resource
token = context.acquire_token_with_username_password(
    RESOURCE, 
    'username',
    'paddword',
    'aad_clientId')

print token
refresh_token = token['refreshToken']

I cannot figure out why. Could you help me to fix it.

@yugangw-msft
Copy link
Contributor

@Walk4Muscle, your account is federated. It is more recommended to use interactively login, check out the sample. Let me know whether this works for you.

@Walk4Muscle
Copy link
Author

So which type of account I can use in the acquire_token_with_username_password function?

@yugangw-msft
Copy link
Contributor

For non-federated accounts acquire_token_with_username_password should just work. For federated accounts, those identities provided through on-prem servers, it is complex because it involves the ADFS server configuration. If you have test accounts we can repro this issue, that will speed up the diagnosis. I can be reached by email: yugangw at microsoft dot com
/CC: @addev-ashish, can you ask your team for whether this is a known issue?

@yugangw-msft
Copy link
Contributor

Also, if you have accounts with 2 factor authentication enforced, acquire_token_with_username_password won't work as well. Interactive login work for any account types.

@MIT02
Copy link

MIT02 commented Jul 7, 2016

Dear yugangw, I have the same problem. Login per credential (username/passord) - without user interaction - is required if a service do the data exchange. I can provide you a test account. Thanks. BR MIT

@yugangw-msft
Copy link
Contributor

@MIT02 I should submit a fix on early next week.

@yugangw-msft
Copy link
Contributor

@MIT02 , @Walk4Muscle, it will take some more days to get the package published out, but you can try out by installing the package from git
pip install https://github.com/yugangw-msft/azure-activedirectory-library-for-python/tarball/federated
And let me know if you see any issues.
The change includes the fix for this issue, and also improves the support on federated accounts particular on wstrust 2005.

@yugangw-msft
Copy link
Contributor

fixed in 0.4

@clp-trap
Copy link

Hello,

i am having the same issue as above to acquire token using acquire_token_with_username_password(python 2.7), i am using the same code.

@MIT02
Copy link

MIT02 commented Jan 26, 2017 via email

@clp-trap
Copy link

I am using the latest version, not working.

@yugangw-msft
Copy link
Contributor

@vogranovic, are you getting the same stack trace?

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

No branches or pull requests

4 participants