azure - 在 Microsoft Identity 平台上以编程方式撤销 Oauth2 访问权限

标签 azure azure-active-directory microsoft-identity-platform azure-identity

所以我正在寻找的是像 Microsoft Identity 平台上的 Google 那样的 Revoke oauth2 访问端点。

基本上,我有一个 App x,它使用 Microsoft 身份平台和图形 API 来获取访问权限并使用用户邮件、日历、联系人等。

当用户希望从我的应用程序中删除其 Microsoft Access 或希望删除其帐户时。

  • 我需要撤销我拥有的访问 token 和刷新 token ,并且我的应用程序应从“Microsoft Portal”中删除-> 隐私 -> 可以访问您的数据的应用程序和服务' 以便用户可以确定集成已被删除。

此功能可通过 google 的 API Google Revoke Access Link 使用。因此,当我使用刷新 token 点击此 api 时,所有访问权限都会被删除,并且我的应用程序会从“google dashboard”中消失。 ->也访问您的数据屏幕的应用程序。

你们能帮我看看这是否可以通过 Microsoft 的 API 获得并指出我的方向吗 谢谢

最佳答案

Revoke-AzureADUserAllRefreshToken 将使为用户生成的应用程序刷新 token 无效,这也会使为用户在浏览器中颁发给 session cookie 的 token 无效。

NOTE: So if the user has access or granted access to the application, Azure AD will generate an access token which has alifetime of one hr.

During this time even if app is deleted ,there are chances it is still available . Azuread issues a refresh token along with access token for the resource.

If this is revoked ,the user wont be able to obtain the token again after the access token expires.

要在访问 token 的生命周期内撤销授权,请检查以下命令。

The cmdlet operates by resetting the refreshTokensValidFromDateTime user property to the current date and time.

例如: 使用 powershell

PS C:\> Revoke-AzureADUserAllRefreshToken -ObjectId "a1dxxxxx-7xx6-4xxd-axxx-b7xxxxxxxa33"
  • 此命令根据以下内容撤销指定用户的刷新 token 用户的对象 ID。

使用 Microsoft graph API 进行相同的操作

POST https://graph.microsoft.com/{version}/users/{userobject_id}/invalidateAllRefreshToken`
  • 如下命令(powershell)撤销当前登录的刷新 token 用户。

    撤销-AzureADSignedInUserAllRefreshToken

  • 作为管理员,您可以从“用户和组”中删除用户 企业应用程序部分。

enter image description here

  • 如果用户已同意应用程序访问应用程序,并且如果 需要用户分配吗?属性下设置为no,那么 用户可以直接进入门户并删除该应用程序。

在上述两种情况下,该用户访问“我的应用”门户时将看不到该应用。

Note:When user assignment is not required, unassigned users don't see the app on their My Apps.

您可以使用以下脚本来 remove a user and role来自应用程序:

$user = get-azureaduser -ObjectId <objectId>
$spo = Get-AzureADServicePrincipal -ObjectId <objectId>

#获取分配给用户取消分配的角色分配ID

$assignments = Get-AzureADServiceAppRoleAssignment -ObjectId $spo.ObjectId | Where {$_.PrincipalDisplayName -eq $user.DisplayName}

#below cmd 将显示指定的高度

$assignments | Select *

#为了删除下面命令的 Approle 分配检查。

Remove-AzureADServiceAppRoleAssignment -ObjectId $spo.ObjectId -AppRoleAssignmentId $assignments[assignment #].ObjectId

引用文献:

  1. Delete oAuth2PermissionGrant (a delegated permission grant) - Microsoft Graph v1.0 | Microsoft Docs
  2. Revoke user access in an emergency in Azure Active Directory - Microsoft Entra | Microsoft Docs

关于azure - 在 Microsoft Identity 平台上以编程方式撤销 Oauth2 访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72629012/

相关文章:

azure - Serilog 无法在 Service Fabric 中工作

azure - Azure Databricks 服务中的 Aml 工作区 ID

javascript - SPA 中的 ADAL JS 强制注销

c# - 尝试使用 Azure Active Directory Identity 连接 Blob 触发器时出现连接字符串不存在错误

azure - 在 Azure 中通过授权保护 Web api 的安全有哪些方法

azure - Visual Studio 发布到 Azure 时出现 Microsoft Identity Platform 错误

c# - Azure Functions #r 仅允许在脚本中使用

.net - 通过SSL卸载应用程序网关连接到Azure托管的ElasticSearch终结点

c# - 如何使用组织身份验证从 Blazor Server 中的身份获取用户属性

c# - 从 NET Core Web 应用程序调用 Microsoft Graph SDK 时出现 MsalUiRequiredException