Azure / Azure/azure-cli

I needed to az logout before az login --scope ... for it to work

Open
#21,519 2 comments 0 reactions 1 assignee Claimed by @jiasli View on GitHub
Account act-identity-squad Auto-Assign customer-reported
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

**Describe the bug**
Minor issue but the guidance given is incorrect/incomplete (at least in my case) for the following error:

AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '_directoryId_'.

The guidance given is:
To re-authenticate, please run:
az login --scope https://management.core.windows.net//.default

This does not fix the problem and the error persists even after multiple attempts. However, if I "az logout" first, then it does work.

**To Reproduce**
I don't actually know why this started happening. I have been using AZ CLI from VS Code PowerShell terminal without any issues and I haven't made any configuration changes to Azure (I am the administrator and the one and only user in the tenant and subscription) and I haven't "moved" to a new location (my physical location and IP address have not changed). But, if you can get yourself in this situation, running "az account tenant list" or "az account subscription list" (and I'm guessing any other online az command) will trigger this error.

**Expected behavior**
The following guidance would have been more complete:
To re-authenticate, please run:
az logout ; az login --scope https://management.core.windows.net//.default

**Environment summary**
Azure CLI 2.34.1; Windows 10 Pro 21H2; PowerShell 7.2.1; VS Code 1.65.0

**Additional context**
I log in to Azure with a Microsoft account. I have multiple directories and the _directoryId_ shown in the error was for the Azure Sphere directory, which is unique among my directories in that it is a special shared directory (azsusers.onmicrosoft.com) not associated specifically with me or with any Azure subscription. It may not be the cause of the error, but whatever the cause, adding "az logout" to the guidance would take care of it and shouldn't hurt anything else :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.