
There are now an insane number of ways to register applications in Azure Active Directory - but many ways are no longer supported or have been discontinued, for example the old Azure PowerShell tools.
However, new tools - for example PowerShell Az - do not support all features, are not well documented or do not behave as expected. In addition, for months there has been a bug in PowerShell that makes the tooling installation take up to 60 minutes! Powershell Gallery slowness: Install-Module -Name Az takes 60 minutes instead of 3
However, one way is still stable and working: the Azure CLI.
Install Azure CLI
Using WinGet:
1winget install -e --id Microsoft.AzureCLI
Using Chocolatey:
1choco install azure-cli
Manual Install: Azure CLI Docs
Login
Login into your Azure Account from CLI:
1az login
or use device code login to use a custom browser window (e.g. multi account feature of your browser):
1az login --use-device-code
Select a subscription
1az account set --subscription $subscriptionId
Create Azure App Registration
When creating the app, it is important to consider what type of app is desired. By default, certain parameters always refer to a web app, e.g. Reply URLs. If a SPA is desired, an update must also take place after the creation!
Create WebApp
1$uri = "https://ba-sample-webapp.azurewebsites.net/"
2$appName = "Benjamin Abt Sample WebApp"
3$appHomepage = "https://ba-sample-webapp.azurewebsites.net/"
4$appReplyUrls = @("https://ba-sample-webapp.azurewebsites.net/",
5 "https://ba-sample-webapp.azurewebsites.net/logout/")
6
7Write-Host "Web App Creating.."
8$app = az ad app create --display-name $appName `
9 --homepage $appHomepage `
10 --reply-urls $appReplyUrls `
11 | ConvertFrom-Json
12Write-Host "Web App $($app.appId) Created."
Create SPA App
1$uri = "https://ba-sample-webapp.azurewebsites.net/"
2$appName = "Benjamin Abt Sample WebApp"
3$appHomepage = "https://ba-sample-webapp.azurewebsites.net/"
4$appReplyUrls = @("https://ba-sample-webapp.azurewebsites.net/",
5 "https://ba-sample-webapp.azurewebsites.net/logout/")
6
7Write-Host "SPA App Creating.."
8$app = az ad app create --display-name $appName `
9 --homepage $appHomepage `
10 | ConvertFrom-Json
11Write-Host "SPA App $($app.appId) Created."
12
13Write-Host "SPA App Updating.."
14# there is no CLI support to add reply urls to a SPA, so we have to patch manually via az rest
15$appPatchUri = "https://graph.microsoft.com/v1.0/applications/{0}" -f $app.objectId
16$appReplyUrlsString = "'{0}'" -f ($appReplyUrls -join "','")
17$appPatchBody = "{spa:{redirectUris:[$appReplyUrlsString]}}"
18az rest --method PATCH --uri $appPatchUri --headers 'Content-Type=application/json' `
19 --body $appPatchBody
20Write-Host "SPA App Updated."
Docs
Conclusion:
It is still very simple and fast to create Azure AD App Registrations, however it is just not well documented.

Comments