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

Get Azure Active Directory application users and roles

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

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

Azure 门户(预览版)

在新的 Azure 门户中,在 "Enterprise applications" >(您的应用程序)> "Users and groups" 下,您现在只会看到分配给该应用程序的用户列表,以及他们被分配到的应用程序角色。您还可以按应用角色进行过滤和排序。这是一个例子:

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

经典 Azure 门户

在应用程序的 "Users and groups" 下,您可以列出所有用户(以及他们的分配状态)以及所有组:

[]

PowerShell

使用新的preview (as of Sept 2016) Azure AD PowerShell module,你可以使用下面的例子:

# 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

Azure AD 图 API

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

列出所有服务主体:

GET https://graph.windows.net/{tenant-id}/servicePrincipals

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

GET https://graph.windows.net/{tenant-id}/servicePrincipals/{object-id}/appRoleAssignments