Azure AD Python - Unexpected polling state invalid_client error

Viewed 714
    store_token = context.acquire_token_with_device_code(resource_uri, code, client_id)
  File "/Users/jyao/Desktop/azureblobtest/lib/python3.7/site-packages/adal/authentication_context.py", line 273, in acquire_token_with_device_code
    return self._acquire_token(token_func)
  File "/Users/jyao/Desktop/azureblobtest/lib/python3.7/site-packages/adal/authentication_context.py", line 109, in _acquire_token
    return token_func(self)
  File "/Users/jyao/Desktop/azureblobtest/lib/python3.7/site-packages/adal/authentication_context.py", line 266, in token_func
    token = token_request.get_token_with_device_code(user_code_info)
  File "/Users/jyao/Desktop/azureblobtest/lib/python3.7/site-packages/adal/token_request.py", line 398, in get_token_with_device_code
    token = client.get_token_with_polling(oauth_parameters, interval, expires_in)
  File "/Users/jyao/Desktop/azureblobtest/lib/python3.7/site-packages/adal/oauth2_client.py", line 345, in get_token_with_polling
    wire_response)
adal.adal_error.AdalError: Unexpected polling state invalid_client

How could I get rid of this error after input the device code and sign-in successfully.

steps:

  1. From a python interactive prompt, run this code [1] (All modules are already loaded). Where:
authority_url = 'https://login.microsoftonline.com/my_tenant_id'
resource_uri = "https://storage.azure.com/"
context = adal.AuthenticationContext(authority_uri)
code = context.acquire_user_code(resource_uri, client_id)
print(code['message'])
store_token = context.acquire_token_with_device_code(resource_uri, code, client_id)
credentials = AADTokenCredentials(store_token, client_id)

2.Open the URL https://microsoft.com/devicelogin in a browser.

3.Enter the code E8B2DVT67

4.Confirm the application's name, it is correct.

5.Authenticate using the user's credentials.

6.Get a message in browser saying "You have signed in to the TEST-APP application on your device. You may now close this window."

7.Get the error shown in my previous message in the python interactive prompt.

I use a native app and update manifest and set "allowPublicClient": true permission.

1 Answers

Your code works fine.

If we set allowPublicClient:false, we will encounter this error.

enter image description here

After updating allowPublicClient to true, it will work. Note: There will be some delay for the configuration to take effect.

enter image description here

Related