AzureAD / azure-activedirectory-library-for-python

ADAL for Python
http://adal-python.readthedocs.io
Other
259 stars 94 forks source link

`UnicodeEncodeError` when calling `acquire_token_with_username_password` with wstrust #250

Closed jiasli closed 3 years ago

jiasli commented 3 years ago

UnicodeError thrown when you do an az login with a username and password. I was using homebrew on my Mac, and thought it was related, so I

docker run -it mcr.microsoft.com/azure-cli

And got the same error.

bash-5.0# az login -u peter.halliday@walgreens.com -p ************
The command failed with an unexpected error. Here is the traceback:
'ascii' codec can't encode characters in position 1617-1618: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 660, in execute
    raise ex
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 723, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 716, in _run_job
    six.reraise(*sys.exc_info())
  File "/usr/local/lib/python3.6/site-packages/six.py", line 703, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 694, in _run_job
    result = cmd_copy(params)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 331, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 811, in default_command_handler
    return op(**command_args)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/command_modules/profile/custom.py", line 162, in login
    use_cert_sn_issuer=use_cert_sn_issuer)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 215, in find_subscriptions_on_login
    username, password, tenant, self._ad_resource_uri)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 885, in find_from_user_account
    token_entry = context.acquire_token_with_username_password(resource, username, password, _CLIENT_ID)
  File "/usr/local/lib/python3.6/site-packages/adal/authentication_context.py", line 164, in acquire_token_with_username_password
    return self._acquire_token(token_func)
  File "/usr/local/lib/python3.6/site-packages/adal/authentication_context.py", line 128, in _acquire_token
    return token_func(self)
  File "/usr/local/lib/python3.6/site-packages/adal/authentication_context.py", line 162, in token_func
    return token_request.get_token_with_username_password(username, password)
  File "/usr/local/lib/python3.6/site-packages/adal/token_request.py", line 285, in get_token_with_username_password
    token = self._get_token_username_password_federated(username, password)
  File "/usr/local/lib/python3.6/site-packages/adal/token_request.py", line 258, in _get_token_username_password_federated
    username, password)
  File "/usr/local/lib/python3.6/site-packages/adal/token_request.py", line 210, in _perform_username_password_for_access_token_exchange
    username, password)
  File "/usr/local/lib/python3.6/site-packages/adal/token_request.py", line 197, in _perform_wstrust_exchange
    result = wstrust.acquire_token(username, password)
  File "/usr/local/lib/python3.6/site-packages/adal/wstrust_request.py", line 169, in acquire_token
    return self._handle_rstr(resp.text)
  File "/usr/local/lib/python3.6/site-packages/adal/wstrust_request.py", line 126, in _handle_rstr
    wstrust_resp.parse()
  File "/usr/local/lib/python3.6/site-packages/adal/wstrust_response.py", line 238, in parse
    token_found = self._parse_token_by_re(self._response)
  File "/usr/local/lib/python3.6/site-packages/adal/wstrust_response.py", line 217, in _parse_token_by_re
    return tokens[0].encode('us-ascii'), token_types[0]
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1617-1618: ordinal not in range(128)

Originally posted by @hoangelos in https://github.com/Azure/azure-cli/issues/17444

rayluo commented 3 years ago

Investigating in its original issue here

jiasli commented 3 years ago

Thanks @rayluo, any chance a new ADAL can be released with the fix https://github.com/Azure/azure-cli/issues/17444#issuecomment-807246119?

rayluo commented 3 years ago

I think so. Earlier today, I've added this case into MSAL's project board. Stay tuned.

CC: @henrik-me @navyasric