I want to authenticate to Azure DevOps using Azure CLI. I can run the following command without issues for one organization, but not for others. I am not using a Personal Access Token (PAT), but rather AAD / Entra authentication.
az rest --resource '499b84ac-1321-427f-aa17-267ca6975798' --url https://dev.azure.com/myorganization/_apis/myproject?api-version=7.1
For one organization, I just get a 203
redirect with HTML for the signin page.
Not a json response, outputting to stdout. For binary data suggest use "--output-file" to write to a file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en-US">
<head><title>
Azure DevOps Services | Sign In
...
I tried executing the command with --debug
, but I don't see any indication of why it does not work. I can run az repos list
for the same organization without any issues.
It turns out I was logged in to the wrong directory. The directory of the DevOps organization was changed recently. My user had access to both the old and the new directory, so I did not notice immediately.
You need to make sure az account show
returns the same tenantId as is configured in Azure Devops. You can use az login --tenant <tenantId> --allow-no-subscriptions
to make sure you are in the correct tenant.
Sidenote: The DevOps extension for AzureCLI seems to automatically try multiple tenants, which is why az devops invoke
and az repos list
worked even when az rest
did not.