【问题标题】:How do I add required permissions to an Azure Active Directory (AAD) application using the Azure PowerShell SDK?如何使用 Azure PowerShell SDK 向 Azure Active Directory (AAD) 应用程序添加所需权限?
【发布时间】:2017-06-17 13:19:03
【问题描述】:

在我的场景中,我正在尝试自动创建我的一个 AAD 应用程序,以便它使用此处为守护进程列出的说明调用另一个 WebAPI 服务(不同的 AAD 应用程序):

https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-daemon/

我已经能够通过 PowerShell 自动创建 AAD 应用程序和所需的访问密钥。

以下是我如何创建添加了密钥的应用程序:

# Generate all the keys (secrets) for the AAD application.
$passwordCredentials = @()

foreach ($key in $activeDirectoryApplication.Keys.Key)
{
    $keyKeyVaultName = $key.KeyVaultName
    $keyName = $key.KeyVaultKeyName
    $expiration = $key.Expiration

    LogInfo "Generating key with key name '$keyName' into key vault '$keyKeyVaultName' with key expiry of '$expiration'."
    $passwordCredential = GenerateActiveDirectoryApplicationKeyPasswordCredential $key
    $passwordCredentials += $passwordCredential

    PublishActiveDirectoryApplicationKeyToKeyVault $key $passwordCredential
}

$existingApplication = New-AzureRmADApplication -DisplayName $applicationName -HomePage $applicationHomePage -IdentifierUris @($applicationIdentifier) -PasswordCredentials $passwordCredentials

我不知道如何自动化上面链接中的第 8 步,它授予访问 WebAPI 应用程序的权限:

  1. 为您的应用程序配置权限 - 在“设置”菜单中,选择“所需权限”部分,单击“添加”,然后选择 API,然后在文本框中键入“TodoListService”。然后,点击选择权限并选择“访问 TodoListService”。

有谁知道 Azure PowerShell SDK 是否可以做到这一点,或者我需要以其他方式(可能是 AAD Graph API)吗?

谢谢!

【问题讨论】:

标签: azure asp.net-web-api permissions azure-active-directory daemon


【解决方案1】:

要分配权限,您需要使用New-AzureRmRoleAssignment。这将允许您在特定范围内为对象(用户\组\应用程序)分配权限。如果你需要内置角色,你很高兴。如果您需要创建角色,请使用New-AzureRmRoleDefinition。

$role = Get-AzureRmRoleDefinition "Virtual Machine Contributor"
$role.Id = $null
$role.Name = "Classic storage reader"
$role.Actions.Clear()
$role.Actions.Add("Microsoft.ClassicStorage/storageAccounts/read")
$role.AssignableScopes.Clear()
$role.AssignableScopes.Add("/subscriptions/xxxx")
New-AzureRmRoleDefinition -Role $role

阅读:
https://docs.microsoft.com/en-us/azure/active-directory/role-based-access-control-manage-access-powershell
https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/new-azurermroleassignment?view=azurermps-4.1.0
https://docs.microsoft.com/en-us/powershell/module/azurerm.resources/new-azurermroledefinition?view=azurermps-4.1.0

【讨论】:

  • 我认为最初的问题是关于 AD App API 权限,而不是关于角色分配。
猜你喜欢
  • 2019-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-23
  • 2016-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多