查看向企业应用程序授予的权限

本文介绍如何查看授予 Microsoft Entra 租户中应用程序的权限。 检测到恶意应用程序或向应用程序授予的权限超过所需权限时,可能需要查看权限。 了解如何使用现有 PowerShell 版本撤销向应用程序授予的权限。

本文中的步骤适用于通过用户或管理员同意添加到 Microsoft Entra 租户的所有应用程序。 有关同意应用程序的详细信息,请参阅用户和管理员同意

先决条件

要查看向应用程序授予的权限,需满足以下条件:

  • 具有活动订阅的 Azure 帐户。 创建帐户
  • 以下角色之一:全局管理员、云应用程序管理员或应用程序管理员。
  • 不是管理员的服务主体所有者能够使刷新令牌失效。

还原权限

有关如何还原已撤销或删除的权限的信息,请参阅还原授予应用程序的权限

查看和撤销权限

提示

本文中的步骤可能因开始使用的门户而略有不同。

可以访问 Microsoft Entra 管理中心来查看授予应用的权限。 可以撤销管理员为整个组织授予的权限,并且可以获取上下文 PowerShell 脚本来执行其他操作。

若要查看已授予整个组织或特定用户或组的应用程序权限,请执行以下操作:

  1. 至少以云应用程序管理员身份登录到 Microsoft Entra 管理中心
  2. 浏览到“标识”>“应用程序”>“企业应用程序”>“所有应用程序”。
  3. 选择想要限制访问的应用程序。
  4. 选择“权限”。
  5. 若要查看适用于整个组织的权限,请选择“管理员同意”选项卡。若要查看授予特定用户或组的权限,请选择“用户同意”选项卡。
  6. 若要查看给定权限的详细信息,请从列表中选择权限。 “权限详细信息”窗格随即打开。 查看向应用程序授予的权限后,可以撤销管理员为整个组织授予的权限。

    注意

    不能通过门户在“用户同意”选项卡中撤销权限。 可以使用 Microsoft Graph API 调用或 PowerShell cmdlet 撤销这些权限。 有关详细信息,请转到本文的 PowerShell 和 Microsoft Graph 选项卡。

若要在“管理员同意”选项卡中撤销权限,请执行以下操作:

  1. 在“管理员同意”选项卡中查看权限列表。
  2. 选择要撤销的权限,然后选择该权限的 ... 控件。 Screenshot shows how to revoke admin consent.
  3. 选择“撤销权限”。

查看和撤销权限

使用以下 Azure AD PowerShell 脚本可撤销向应用程序授予的所有权限。 至少需要云应用程序管理员登录。

Connect-AzureAD -AzureEnvironmentName AzureChinaCloud

# Get Service Principal using objectId
$sp = Get-AzureADServicePrincipal -ObjectId "<ServicePrincipal objectID>"

# Get all delegated permissions for the service principal
$spOAuth2PermissionsGrants = Get-AzureADOAuth2PermissionGrant -All $true| Where-Object { $_.clientId -eq $sp.ObjectId }

# Remove all delegated permissions
$spOAuth2PermissionsGrants | ForEach-Object {
    Remove-AzureADOAuth2PermissionGrant -ObjectId $_.ObjectId
}

# Get all application permissions for the service principal
$spApplicationPermissions = Get-AzureADServiceAppRoleAssignedTo -ObjectId $sp.ObjectId -All $true | Where-Object { $_.PrincipalType -eq "ServicePrincipal" }

# Remove all application permissions
$spApplicationPermissions | ForEach-Object {
    Remove-AzureADServiceAppRoleAssignment -ObjectId $_.PrincipalId -AppRoleAssignmentId $_.objectId
}

使刷新令牌失效

使用以下脚本为应用程序的用户或组删除 appRoleAssignments。

Connect-AzureAD -AzureEnvironmentName AzureChinaCloud

# Get Service Principal using objectId
$sp = Get-AzureADServicePrincipal -ObjectId "<ServicePrincipal objectID>"

# Get Azure AD App role assignments using objectID of the Service Principal
$assignments = Get-AzureADServiceAppRoleAssignment -ObjectId $sp.ObjectId -All $true | Where-Object {$_.PrincipalType -eq "User"}

# Revoke refresh token for all users assigned to the application
$assignments | ForEach-Object {
    Revoke-AzureADUserAllRefreshToken -ObjectId $_.PrincipalId
}

查看和撤销权限

使用以下 Microsoft Graph PowerShell 脚本可撤销向应用程序授予的所有权限。 至少需要云应用程序管理员登录。

Connect-MgGraph -Environment China -Scopes "Application.ReadWrite.All", "Directory.ReadWrite.All", "DelegatedPermissionGrant.ReadWrite.All", "AppRoleAssignment.ReadWrite.All"

# Get Service Principal using objectId
$sp = Get-MgServicePrincipal -ServicePrincipalID "$ServicePrincipalID"

Example: Get-MgServicePrincipal -ServicePrincipalId '22c1770d-30df-49e7-a763-f39d2ef9b369'

# Get all delegated permissions for the service principal
$spOAuth2PermissionsGrants= Get-MgOauth2PermissionGrant -All| Where-Object { $_.clientId -eq $sp.Id }

# Remove all delegated permissions
$spOauth2PermissionsGrants |ForEach-Object {
  Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId $_.Id
  }

# Get all application permissions for the service principal
$spApplicationPermissions = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $Sp.Id -All | Where-Object { $_.PrincipalType -eq "ServicePrincipal" }

# Remove all application permissions
$spApplicationPermissions | ForEach-Object {
Remove-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $Sp.Id  -AppRoleAssignmentId $_.Id
 }

使刷新令牌失效

使用以下脚本为应用程序的用户或组删除 appRoleAssignments。

Connect-MgGraph -Environment China -Scopes "Application.ReadWrite.All", "Directory.ReadWrite.All", "AppRoleAssignment.ReadWrite.All"

# Get Service Principal using objectId
$sp = Get-MgServicePrincipal -ServicePrincipalID "$ServicePrincipalID"

Example: Get-MgServicePrincipal -ServicePrincipalId '22c1770d-30df-49e7-a763-f39d2ef9b369'

# Get Azure AD App role assignments using objectID of the Service Principal
$spApplicationPermissions = Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalID $sp.Id -All | Where-Object { $_.PrincipalType -eq "ServicePrincipal" }

# Revoke refresh token for all users assigned to the application
  $spApplicationPermissions | ForEach-Object {
  Remove-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $_.PrincipalId -AppRoleAssignmentId $_.Id
  }

注意

撤消当前所授予的权限不会阻止用户再次同意该应用程序。 如果要阻止用户同意,请阅读配置用户同意应用程序的方式

后续步骤