简体   繁体   English

使用 Azure CLI 注册应用程序后,在 PowerShell 中创建管理员同意会出错

[英]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创建应用程序后,我添加了 admin-consent - 但在最后一行失败

$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

在此处输入图像描述

If run this command in the shell - it works fine.如果在 shell 中运行此命令 - 它工作正常。


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

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.使用az account show确保您在 powershell 中登录了正确的管理员帐户,并在创建应用程序时尝试指定--identifier-uris

$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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM