user2347380
user2347380

Reputation: 115

Creating admin-consent in PowerShell after app registration with Azure CLI make an error

After I created an app I add admin-consent - but it failed on last line

$myApiAppRegistration = az ad app create --display-name $appName --password $secret --reply-urls $replyUrl --required-resource-accesses $resources --available-to-other-tenants false

$myApiAppRegistrationResult = ($myApiAppRegistration | ConvertFrom-Json)

az ad app permission admin-consent --id $myApiAppRegistrationResult.appId

enter image description here

If run this command in the shell - it works fine.


I found the problem - sometime timeout is required.

Write-Host ' Create Service Principal'
Start-Sleep -Seconds 5
az ad sp create --id $appId
Start-Sleep -Seconds 5
Write-Host ' Add Permission grant'
az ad app permission grant --id $appId --api $graphId
Start-Sleep -Seconds 5
Write-Host ' Admin consent. AppId:'  $appId
az ad app permission admin-consent --id $appId

Upvotes: 1

Views: 531

Answers (2)

user2347380
user2347380

Reputation: 115

Before granting consent I have to:

-- Service Principal
az ad sp create --id $appId |Out-Null

-- Grant Permissions
az ad app permission grant --id $appId --api $graphId

Upvotes: 0

Joy Wang
Joy Wang

Reputation: 42043

Use az account show to make sure you logged in the correct admin account in the powershell, and try to specify the --identifier-uris when you creating the app.

$myApiAppRegistration = az ad app create --display-name $appName --password $secret --reply-urls $replyUrl --identifier-uris 'https://testapp777' --required-resource-accesses $resources --available-to-other-tenants false

Upvotes: 1

Related Questions