question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

az account get-access-token fails in Azure Cloud Shell

See original GitHub issue

Description

Outline the issue here: Install the newer version of the az CLI client in the Azure cloud shell (the usual curl | bash install) and put it in the path. Try running:

$ az account get-access-token.

This produces "isMRRT" error: 
uros@Azure:~$ az account get-access-token 
'isMRRT'
Traceback (most recent call last):
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/main.py", line 36, in main
    cmd_result = APPLICATION.execute(args)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/core/application.py", line 210, in execute
    result = expanded_arg.func(params)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/core/commands/__init__.py", line 289, in __call__
    return self.handler(*args, **kwargs)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/core/commands/__init__.py", line 488, in _execute_command
    reraise(*sys.exc_info())
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/six.py", line 686, in reraise
    raise value
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/core/commands/__init__.py", line 465, in _execute_command
    result = op(client, **kwargs) if client else op(**kwargs)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/command_modules/profile/custom.py", line 54, in get_access_token
    resource=resource)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/core/_profile.py", line 334, in get_raw_token
    account[_TENANT_ID], resource)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/azure/cli/core/_profile.py", line 522, in retrieve_token_for_user
    token_entry = context.acquire_token(resource, username, _CLIENT_ID)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/authentication_context.py", line 126, in acquire_token
    return self._acquire_token(token_func)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/authentication_context.py", line 109, in _acquire_token
    return token_func(self)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/authentication_context.py", line 124, in token_func
    return token_request.get_token_from_cache_with_refresh(user_id)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/token_request.py", line 350, in get_token_from_cache_with_refresh
    return self._find_token_from_cache()
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/token_request.py", line 128, in _find_token_from_cache
    return self._cache_driver.find(cache_query)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/cache_driver.py", line 179, in find
    entry, is_resource_tenant_specific = self._load_single_entry_from_cache(query)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/cache_driver.py", line 112, in _load_single_entry_from_cache
    token = next(mrrt_tokens, None)
  File "/home/uros/lib/azure-cli/lib/python3.5/site-packages/adal/cache_driver.py", line 111, in <genexpr>
    mrrt_tokens = (x for x in potential_entries if x[TokenResponseFields.IS_MRRT])
KeyError: 'isMRRT'

Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: curl | bash

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: az --version azure-cli (2.0.7)

acr (2.0.5) acs (2.0.7) appservice (0.1.7) batch (3.0.0) billing (0.1.0) cdn (0.0.3) cloud (2.0.3) cognitiveservices (0.1.3) command-modules-nspkg (2.0.0) component (2.0.5) configure (2.0.7) consumption (0.1.0) core (2.0.7) cosmosdb (0.1.7) dla (0.0.7) dls (0.0.7) feedback (2.0.3) find (0.2.3) interactive (0.3.3) iot (0.1.6) keyvault (2.0.5) lab (0.0.5) monitor (0.0.5) network (2.0.7) nspkg (3.0.0) profile (2.0.5) rdbms (0.0.2) redis (0.2.4) resource (2.0.7) role (2.0.5) sf (1.0.2) sql (2.0.4) storage (2.0.7) vm (2.0.7)

Python (Linux) 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609]

Python location ‘/home/uros/lib/azure-cli/bin/python’

OS Version: What OS and version are you using?
Answer here: No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: bash

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
yugangw-msftcommented, Jul 13, 2017

The get-access-token is not supported to be used in cloud-shell, but i will fix that still. EDIT The fix will be in adal-python though. The fix was made in CLI 1.0 integrated by cloud console

0reactions
thangduongcommented, Jun 20, 2018

And 7 months later, the problem still happens: thang@Azure:~$ az ml env show -g MLModelHosting-rd-rg -n deploy1 A Cloud Shell credential problem occurred. When you report the issue with the error below, please mention the hostname ‘cc-efbb97af-236349040-krskc’ { “Azure-cli-ml Version”: “0.1.0a27.post3”, “Error”: “Could not retrieve token from local cache.” }

Great work guys.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CloudShell get-access-token error - Failed to connect to MSI
Describe the bug When requesting an access token from admin.microsoft.com az cli fails. Command Name az account get-access-token Errors: ...
Read more >
Azure Cloud Shell troubleshooting | Microsoft Learn
Details: When creating a storage account through Cloud Shell, it's unsuccessful due to an Azure Policy assignment placed by your admin.
Read more >
Acquiring a user token in Azure Cloud Shell - Microsoft Learn
How to acquire a token for the authenticated user in Azure Cloud Shell. ... you can do so using az login or Connect-AzAccount...
Read more >
Get-AzAccessToken (Az.Accounts) | Microsoft Learn
Module: Az.Accounts. Get raw access token. When using -ResourceUrl, please make sure the value does match current Azure environment.
Read more >
Get Azure AD tokens for service principals - Microsoft Learn
Generate the Azure AD access token for the signed-in Azure AD service principal by running the az account get-access-token command.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found