获取 Azure Active Directory 应用程序用户和角色

Jer*_*emy 4 azure azure-active-directory azure-ad-graph-api

我已在 Azure AD Premium 中设置了一个应用程序,并进行了访问该应用程序所需的用户分配。我已将自定义应用程序角色添加到应用程序清单中。我可以为应用程序分配具有角色的用户。

如何获得分配给应用程序的所有用户及其分配的角色的列表?

Phi*_*ret 8

Azure 门户(预览)

在新的 Azure 门户中,在“企业应用程序”>(您的应用程序)>“用户和组”下,您现在将只看到分配给应用程序的用户列表,以及他们分配给的应用程序角色. 您还可以按应用程序角色过滤和排序。下面是一个例子:

Azure 门户 / 企业应用程序 / 用户和组

注意:截至 2016 年 9 月,新 Azure 门户中的 Azure AD 管理体验处于预览阶段。

经典 Azure 门户

在应用程序的“用户和组”下,您可以列出所有用户(以及他们的分配状态)以及所有组:

[经典 Azure 门户/Active Directory/应用程序/用户和组]

电源外壳

使用新的预览版(截至 2016 年 9 月)Azure AD PowerShell 模块,您可以使用以下示例:

# Get all service principals, and for each one, get all the app role assignments, 
# resolving the app role ID to it's display name. Output everything to a CSV.
Get-AzureADServicePrincipal | % {

  # Build a hash table of the service principal's app roles. The 0-Guid is
  # used in an app role assignment to indicate that the principal is assigned
  # to the default app role (or rather, no app role).
  $appRoles = @{ "$([Guid]::Empty.ToString())" = "(default)" }
  $_.AppRoles | % { $appRoles[$_.Id] = $_.DisplayName }

  # Get the app role assignments for this app, and add a field for the app role name
  Get-AzureADServiceAppRoleAssignment -ObjectId ($_.ObjectId) | % {
    $_ | Add-Member "AppRoleDisplayName" $appRoles[$_.Id] -Passthru
  }
} | Export-Csv "app_role_assignments.csv" -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)

Azure AD 图形 API

使用 Azure AD Graph API,您可以执行与上面 PowerShell 脚本相同的操作(实际上,新的 Azure AD PowerShell 模块对大多数请求使用 Azure AD Graph API)。

列出所有服务主体:

GET https://graph.windows.net/{tenant-id}/servicePrincipals
Run Code Online (Sandbox Code Playgroud)

列出服务主体的应用程序角色分配:

GET https://graph.windows.net/{tenant-id}/servicePrincipals/{object-id}/appRoleAssignments
Run Code Online (Sandbox Code Playgroud)