AzureAuth is a generic Azure credential provider. It currently supports the following modes of public client authentication (i.e., authenticating a human user.)
- IWA (Integrated Windows Authentication)
- WAM (Web Account Manager) (Windows only brokered authentication)
- Embedded Web View (Windows Only)
- System Web Browser (Used on OSX in-place of Embedded Web View)
- Device Code Flow (All platforms, terminal interface only).
The azureauth aad
subcommand is a "pass-through" for using MSAL.NET. This means it does not provide any client ID (aka app registration) by default. You must register and configure your own app registration to authenticate with.
-
Follow this quick start guide to setup your application.
-
Configure redirect URIs for WAM (the Windows broker)
- Select the Authentication blade.
- Under Platform configurations, select Add a platform.
- In the Configure platforms pane, select Mobile and desktop applications.
- In the Configure Desktop + devices pane, under Custom redirect URIs, specify
ms-appx-web://Microsoft.AAD.BrokerPlugin/<ClientID>
- Select Configure.
-
Configure redirect URIs for the system web browser
- Select the Authentication blade.
- Under Platform configurations, find Mobile and desktop applications
- Select Add URI and enter
(Note — do not use
http://localhost
https
here as this is for local redirect and TLS won't work.) - Select Save.
-
To support public client auth modes enable the Allow public client flows setting, in the Authentication blade.
You always need to pass at least these three arguments in order to authenticate as something (client id), to something (resource ID), within some AAD tenant. These IDs can be found in the Azure Portal on the Overview of each application/resource/tenant in the AAD section.
- A client ID. It is a unique application (client) ID assigned to your app by Azure AD when the app was registered.
- A resource ID. It is a unique ID representing the resource which you want to authenticate to.
- A tenant ID. (This is found on the main AAD page within the Azure Portal)
They can either be provided explicitly on the CLI or they can be given implicitly as part of a config file when given an alias.
AzureAuth config files use the TOML file format. Here is a sample config file.
[alias.alias1]
# The resource ID
resource = "67eeda51-3891-4101-a0e3-bf0c64047157"
# The client ID
client = "73e5793e-8f71-4da2-9f71-575cb3019b37"
domain = "contoso.com"
tenant = "a3be859b-7f9a-4955-98ed-f3602dbd954c"
[alias.alias2]
resource = "ab7e45b7-ea4c-458c-97bd-670ccb543376"
client = "73e5793e-8f71-4da2-9f71-575cb3019b37"
domain = "fabrikam.com"
tenant = "a3be859b-7f9a-4955-98ed-f3602dbd954c"
Usage:
azureauth aad --alias alias1 --config <path to the config file>
or if you set the environment variable AZUREAUTH_CONFIG
to the config file path, you can omit the option --config
and use the below command.
azureauth aad --alias alias1
"Shelling out" (executing as a subprocess) to AzureAuth CLI is highly recommended to have the best possible authentication experience. This insulates your application from potentially lots of dependency headaches, and churn as the authentication libraries used under the hood update, as do the means of authenticating.
Use the option --output
to get the token in the desired formats. Available choices:
--output token
returns token in plain text.--output json
returns a JSON string of the following format:{ "user": "<user@example.com>", "display_name": "User Name", "token": "<encoded token>", "expiration_date": "<expiration date in unix format>" }
--output status
returns the status of the authentication and the cache.--output none
returns nothing.
Azureauth defaults to a 15 minute timeout. You can override this with a custom timeout value using --timeout
. The value is interpreted as a decimal number of minutes. The example below will wait 10 minutes and 45 seconds.
Usage:
azureauth aad --alias alias1 --timeout 10.75
Use the command azureauth aad --help
to understand more available options.
- Sample python code available here.
- Sample command to authenticate your client to a resource under a tenant.
azureauth aad --client <clientID> --resource <resourceID> --tenant <tenantID> --output <output format>
The azureauth ado
subcommand is a logical grouping for two subcommands,
azureauth ado pat
and azureauth ado token
.
The azureauth ado pat
subcommand is designed to create and cache Azure DevOps
Personal Access Tokens (PATs) using encrypted local storage.
At a minimum users must specify
- The
--organization
the PAT is for. - The
--display-name
of the PAT. - The intended
--scope
of the PAT (you can specify multiple). - A
--prompt-hint
which can be displayed if an interactive prompt is required.
Here is an example invocation:
azureauth ado pat --organization Contoso --display-name NuGetPackages --scope vso.packaging --prompt-hint NuGetPackages
PATs created by the azureauth ado pat
subcommand are valid for up to a week.
During that time requests for the same organization
, display-name
, scope
combo will yield a cached PAT. If the PAT would expire within 48 hours then a
new PAT is generated and the old PAT is invalidated.
The azureauth ado token
subcommand is designed for scenarios where the calling
application doesn't care what kind of Azure DevOps token it receives. It is most
useful in scripts that normally run as part of an automated pipeline, but that
are occassionally triggered manually by users as well.
Under normal circumstances the azureauth ado token
subcommand functions like
a built-in alias for azureauth aad
which provides Azure DevOps defaults. That
is,
azureauth ado token
should be considered equivalent to
azureauth aad --client <default ADO client> --tenant <tenantID> --scope <default ADO scope>
However, the azureauth ado token
subcommand will also detect a Personal Access
Token (PAT) in environment variables and output that instead if it is available.
This is particularly useful when combined with the --output
flag. For example,
if you choose the header
output option the subcommand will correctly choose
between formatting the output for Authorization: Bearer
or
Authorization: Basic
depending on the token type.
Both the AZUREAUTH_ADO_PAT
and SYSTEM_ACCESSTOKEN
environment variables are
respected as sources for a PAT.
The azureauth info
subcommand displays information about your AzureAuth
installation. Presently this is limited to application version and telemetry
device ID. This device ID is only used when telemetry is enabled (it's off by
default). You can reset the ID with
azureauth info reset-device-id