Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Register Microsoft Entra ID apps and configure OAuth 2.0 authentication with MSAL integration.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/cli-commands.md
1# Azure CLI Commands for App Registration23This document provides a comprehensive reference for managing Microsoft Entra app registrations using Azure CLI.45## Prerequisites67```bash8# Ensure Azure CLI is installed9az version1011# Login to Azure12az login1314# Set default subscription (optional)15az account set --subscription "Your Subscription Name"16```1718## App Registration Management1920### Create App Registration2122**Basic app registration:**23```bash24az ad app create --display-name "MyApplication"25```2627**Web application with redirect URI:**28```bash29az ad app create \30--display-name "MyWebApp" \31--web-redirect-uris "https://myapp.com/callback" \32--sign-in-audience "AzureADMyOrg"33```3435**Single Page Application (SPA):**36```bash37az ad app create \38--display-name "MySpaApp" \39--spa-redirect-uris "http://localhost:3000" \40--sign-in-audience "AzureADMyOrg"41```4243**Public client (Desktop/Mobile app):**44```bash45az ad app create \46--display-name "MyDesktopApp" \47--public-client-redirect-uris "http://localhost" \48--sign-in-audience "AzureADMyOrg"49```5051**Multi-tenant application:**52```bash53az ad app create \54--display-name "MyMultiTenantApp" \55--web-redirect-uris "https://myapp.com/callback" \56--sign-in-audience "AzureADMultipleOrgs"57```5859### Sign-in Audience Options6061| Value | Description |62|-------|-------------|63| `AzureADMyOrg` | Single tenant (default) |64| `AzureADMultipleOrgs` | Multi-tenant (any Azure AD) |65| `AzureADandPersonalMicrosoftAccount` | Multi-tenant + personal Microsoft accounts |66| `PersonalMicrosoftAccount` | Personal Microsoft accounts only |6768## List and Query Apps6970### List all app registrations7172```bash73az ad app list --output table74```7576### List apps with custom query7778```bash79# Filter by display name80az ad app list --display-name "MyApp" --output table8182# Get specific fields83az ad app list --query "[].{Name:displayName, AppId:appId}" --output table84```8586### Get app details8788```bash89# By display name90az ad app show --id $(az ad app list --display-name "MyApp" --query "[0].appId" -o tsv)9192# By application ID93az ad app show --id "YOUR_APPLICATION_ID"94```9596### Get Application (Client) ID9798```bash99APP_ID=$(az ad app list --display-name "MyApp" --query "[0].appId" -o tsv)100echo "Application ID: $APP_ID"101```102103### Get Object ID104105```bash106OBJECT_ID=$(az ad app list --display-name "MyApp" --query "[0].id" -o tsv)107echo "Object ID: $OBJECT_ID"108```109110## Update App Registration111112### Add redirect URIs113114**Web app:**115```bash116az ad app update --id $APP_ID \117--web-redirect-uris "https://myapp.com/callback" "https://myapp.com/auth"118```119120**SPA:**121```bash122az ad app update --id $APP_ID \123--spa-redirect-uris "http://localhost:3000" "http://localhost:5000"124```125126**Public client:**127```bash128az ad app update --id $APP_ID \129--public-client-redirect-uris "http://localhost" "myapp://auth"130```131132## Client Credentials (Secrets & Certificates)133134### Create client secret135136```bash137# Create secret with default expiration138az ad app credential reset --id $APP_ID139140# Create secret with custom expiration141az ad app credential reset --id $APP_ID --years 1142143# Create secret with specific end date144az ad app credential reset --id $APP_ID --end-date "2025-12-31"145```146147**Save the output:**148```json149{150"appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",151"password": "your-secret-value-SAVE-THIS",152"tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"153}154```155156**⚠️ Important:** Resetting Client credential will delete all existing credentials.157**⚠️ Important:** The secret value is only shown once. Store it securely (e.g., Azure Key Vault).158159### List client credentials160161```bash162# List all credentials (secrets and certificates)163az ad app credential list --id $APP_ID164```165166### Delete client secret167168```bash169# Get key ID from credential list170az ad app credential list --id $APP_ID --query "[].{KeyId:keyId, Type:type}" -o table171172# Delete specific credential173az ad app credential delete --id $APP_ID --key-id "KEY_ID_HERE"174```175176### Upload certificate177178```bash179# Upload certificate from file180az ad app credential reset --id $APP_ID --cert "@path/to/cert.pem"181```182183## API Permissions184185### Add API permissions186187**Microsoft Graph User.Read:**188```bash189GRAPH_RESOURCE_ID="00000003-0000-0000-c000-000000000000" # Microsoft Graph190USER_READ_ID="e1fe6dd8-ba31-4d61-89e7-88639da4683d" # User.Read permission191192az ad app permission add --id $APP_ID \193--api $GRAPH_RESOURCE_ID \194--api-permissions "$USER_READ_ID=Scope"195```196197**Microsoft Graph Mail.Read (delegated):**198```bash199MAIL_READ_ID="570282fd-fa5c-430d-a7fd-fc8dc98a9dca" # Mail.Read permission200201az ad app permission add --id $APP_ID \202--api $GRAPH_RESOURCE_ID \203--api-permissions "$MAIL_READ_ID=Scope"204```205206**Microsoft Graph User.Read.All (application):**207```bash208USER_READ_ALL_ID="df021288-bdef-4463-88db-98f22de89214" # User.Read.All application permission209210az ad app permission add --id $APP_ID \211--api $GRAPH_RESOURCE_ID \212--api-permissions "$USER_READ_ALL_ID=Role"213```214215**Note:** Use `Scope` for delegated permissions, `Role` for application permissions.216217### Common Permission IDs218219**Microsoft Graph (00000003-0000-0000-c000-000000000000):**220221| Permission | ID | Type |222|------------|-----|------|223| User.Read | e1fe6dd8-ba31-4d61-89e7-88639da4683d | Delegated |224| User.ReadWrite | b4e74841-8e56-480b-be8b-910348b18b4c | Delegated |225| Mail.Read | 570282fd-fa5c-430d-a7fd-fc8dc98a9dca | Delegated |226| Mail.Send | e383f46e-2787-4529-855e-0e479a3ffac0 | Delegated |227| Calendars.Read | 465a38f9-76ea-45b9-9f34-9e8b0d4b0b42 | Delegated |228| User.Read.All | df021288-bdef-4463-88db-98f22de89214 | Application |229| Directory.Read.All | 7ab1d382-f21e-4acd-a863-ba3e13f7da61 | Application |230231### Grant admin consent232233```bash234# Grant admin consent for all permissions235az ad app permission admin-consent --id $APP_ID236```237238**Note:** Admin consent is required for application permissions and some delegated permissions.239240### List permissions241242```bash243az ad app permission list --id $APP_ID244```245246### Delete permission247248```bash249# Remove specific permission250az ad app permission delete --id $APP_ID \251--api $GRAPH_RESOURCE_ID \252--permission-id $USER_READ_ID253```254255## Service Principal Management256257### Create service principal258259```bash260# Create service principal for the app261az ad sp create --id $APP_ID262```263264### List service principals265266```bash267az ad sp list --display-name "MyApp"268```269270### Get service principal details271272```bash273az ad sp show --id $APP_ID274```275276### Delete service principal277278```bash279az ad sp delete --id $APP_ID280```281282## App Roles and Claims283284### Get app roles285286```bash287az ad app show --id $APP_ID --query "appRoles"288```289290### Get optional claims291292```bash293az ad app show --id $APP_ID --query "optionalClaims"294```295296## Owners297298### List app owners299300```bash301az ad app owner list --id $APP_ID302```303304### Add owner305306```bash307# Add user as owner308USER_OBJECT_ID=$(az ad user show --id "[email protected]" --query "id" -o tsv)309az ad app owner add --id $APP_ID --owner-object-id $USER_OBJECT_ID310```311312### Remove owner313314```bash315az ad app owner remove --id $APP_ID --owner-object-id $USER_OBJECT_ID316```317318## Delete App Registration319320```bash321# Delete app registration (and associated service principal)322az ad app delete --id $APP_ID323```324325## Tenant and Identity Information326327### Get tenant ID328329```bash330az account show --query tenantId -o tsv331```332333### Get current user information334335```bash336az ad signed-in-user show337```338339### Get user by email340341```bash342az ad user show --id "[email protected]"343```344345### Get user object ID346347```bash348az ad user show --id "[email protected]" --query "id" -o tsv349```350351### List all users352353```bash354az ad user list --output table355```356357## Scripting Examples358359### Complete app setup script360361```bash362#!/bin/bash363364# Variables365APP_NAME="MyApplication"366REDIRECT_URI="http://localhost:3000"367368echo "Creating app registration..."369APP_ID=$(az ad app create \370--display-name "$APP_NAME" \371--spa-redirect-uris "$REDIRECT_URI" \372--query "appId" -o tsv)373374echo "App created with ID: $APP_ID"375376echo "Adding Microsoft Graph permissions..."377GRAPH_RESOURCE_ID="00000003-0000-0000-c000-000000000000"378USER_READ_ID="e1fe6dd8-ba31-4d61-89e7-88639da4683d"379380az ad app permission add --id $APP_ID \381--api $GRAPH_RESOURCE_ID \382--api-permissions "$USER_READ_ID=Scope"383384echo "Granting admin consent..."385az ad app permission admin-consent --id $APP_ID386387echo "Creating service principal..."388az ad sp create --id $APP_ID389390TENANT_ID=$(az account show --query tenantId -o tsv)391392echo ""393echo "App registration complete!"394echo "Application (Client) ID: $APP_ID"395echo "Tenant ID: $TENANT_ID"396echo "Redirect URI: $REDIRECT_URI"397```398399### Cleanup script400401```bash402#!/bin/bash403404# Delete all apps matching pattern405az ad app list --display-name "Test*" --query "[].appId" -o tsv | while read APP_ID; do406echo "Deleting app: $APP_ID"407az ad app delete --id $APP_ID408done409```410