是否有人知道可以为 Azure AD 用户管理角色的工具
AFAIK,没有任何特定工具可用于管理应用程序角色。
总体而言,您应该能够使用以下选项来添加/编辑/更新与应用程序角色相关的选项并将权限分配给现有 AD 用户:
注意:如果您要处理大量用户,您可以考虑将安全组分配给应用角色,而不是为单个用户分配安全组。这是一个值得考虑的选项,尽管它需要 Azure AD 高级许可证。 (更新 - 另请参阅此答案末尾 Philippe Signoret 关于将组分配给应用角色、委派管理分配的组和self-service group management 的评论)
通过编辑应用程序清单 json 的 Azure 门户(您已经知道这一点)
-
PowerShell -
我在最后添加了一个脚本。您可以在使用New-AzureADApplication 创建新应用或使用Set-AzureADApplication 为现有应用创建新应用时执行此操作。
要将这些角色分配给现有用户,您可以使用New-AzureADUserAppRoleAssignment,如下面的更新脚本所示。
-
Azure AD 图形 API -
您可以使用 AppRole 类型和应用程序实体来管理应用角色本身。 Documentation here
您可以使用 AppRoleAssignment Entity 将这些角色分配给现有的 Azure AD 用户等。Documentation here
-
微软图形 API -
Documentation here - 请注意这仅在 beta 版本中可用 - 所以它还不适合生产应用程序。
在这里寻找working with App Role Assignments
对于您的生产应用程序,您可以从 json 文件(源代码控制的一部分,如 git 等)读取应用程序角色,并将其提供给 PowerShell 或 Azure AD Graph API 等编程选项之一。
这是 PowerShell 脚本。还可以查看这些 SO Post,我们在其中讨论了类似但仅在 PowerShell 范围内的内容。
SO Post 1
SO Post 2(本题讨论解析 json 文件和使用 PowerShell 更新应用程序清单)
Connect-AzureAD -TenantId <Tenant GUID>
# Create an application role of given name and description
Function CreateAppRole([string] $Name, [string] $Description)
{
$appRole = New-Object Microsoft.Open.AzureAD.Model.AppRole
$appRole.AllowedMemberTypes = New-Object System.Collections.Generic.List[string]
$appRole.AllowedMemberTypes.Add("User");
$appRole.DisplayName = $Name
$appRole.Id = New-Guid
$appRole.IsEnabled = $true
$appRole.Description = $Description
$appRole.Value = $Name;
return $appRole
}
# ObjectId for application from App Registrations in your AzureAD
$appObjectId = "<Your Application Object Id>"
$app = Get-AzureADApplication -ObjectId $appObjectId
$appRoles = $app.AppRoles
Write-Host "App Roles before addition of new role.."
Write-Host $appRoles
$newRole = CreateAppRole -Name "MyNewApplicationRole" -Description "This is my new Application Role"
$appRoles.Add($newRole)
Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $appRoles
完成上述脚本以添加 AppRole 后,为用户分配角色非常简单,并且可以使用直接命令。这是一个示例脚本 -
# Assign the values to the variables
$username = "<You user's UPN>"
$app_name = "<Your App's display name>"
$app_role_name = "<App role display name>"
# Get the user to assign, and the service principal for the app to assign to
$user = Get-AzureADUser -ObjectId "$username"
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }
# Assign the user to the app role
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId
$user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id