c# - 还原已删除的目录 Azure Active Directory 对象 - Azure Graph API

标签 c# azure azure-active-directory azure-ad-graph-api

我们有一个针对本地 AD 的清理流程,要求删除本地帐户,同时保留 Azure 服务的单点登录。 这意味着我们需要能够将 Azure 帐户转换为“云托管”帐户。

我的研究(以及成功的测试)表明,这可以通过将本地用户移动到 dirsync 范围之外的 OU 来实现。

问题是,虽然此操作实现了向“云托管”的理想转换,但它还将 Azure 帐户移动到“DeletedObjects”

如何以编程方式从DeletedObjects 中恢复纯云帐户? (Microsoft.Azure.ActiveDirectory.GraphClient v 2.1.1)

    public static bool RestoreDeletedUser(Guid ObjectId)
    {
        ActiveDirectoryClient activeDirectoryClient = AuthenticationHelper.GetActiveDirectoryClientAsApplication();
        Task<IPagedCollection<IDirectoryObject>> userQuery = activeDirectoryClient.DeletedDirectoryObjects.Where(u => u.ObjectId.Equals(ObjectId.ToString())).ExecuteAsync();
        userQuery.Wait();
        IPagedCollection<IDirectoryObject> userQueryResult = userQuery.Result;
        List<IDirectoryObject> user = userQueryResult.CurrentPage.ToList();
        if (user.Count == 1)
        {
            user.First().restore(); //What do I do here? .restore is not a function.
        }
        return false;
    }

最佳答案

您可以通过较新的 Microsoft Graph API https://graph.microsoft.com 或其 SDK 恢复已删除的用户。我将很快介绍底层 API 和相关代码。

我认为旧版 Azure AD Graph API https://graph.windows.net 或其 SDK提供恢复功能,这就是您当前的代码正在使用的。我没有在任何地方明确指出这一点,因此我可能对此有误,但我这样说是基于两件事:

  • Microsoft 针对旧版 Azure AD Graph 和新版 Microsoft Graph API 的比较博客 - Microsoft Graph or the Azure AD Graph (看对比表)

    enter image description here

  • Azure AD Graph API 文档 - 我可以看到应用程序对象中提到的一些恢复功能 here但与用户无关。又查看了客户端SDK代码,找不到任何恢复方法。

总的来说,强烈建议使用较新的 Microsoft Graph API 而不是较旧的 Azure AD Graph API,您可以在上述链接中阅读。

如何使用 Microsoft Graph API 恢复用户

使用.NET客户端SDK

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

await graphClient.Directory.DeletedItems["{object-id}"]
    .Restore()
    .Request()
    .PostAsync()

底层 API - Restore deleted item

POST https://graph.microsoft.com/v1.0/directory/deletedItems/{id}/restore

关于c# - 还原已删除的目录 Azure Active Directory 对象 - Azure Graph API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56299854/

相关文章:

c# - asp updatepanel 中的文本框焦点 - 使用断点但并非没有

git - 从发布 (CD) 管道触发构建 (CI) 管道?

azure - ADF 在 git 模式下发布困惑

azure - IIS 上托管的应用程序中的身份验证思想 Azure AD

c# - 创建我自己的自定义异常有哪些最佳实践?

c# - 在音频文件中查找音频样本(频谱图已存在)

c# - Azure函数: how to efficiently send batch of messages to Service Bus using bindings?

azure : Permission for Service Principal to get list of Service Principals

azure-active-directory - Get-AzureADServicePrincipal 需要哪些权限?

azure - 如何配置 Azure AD 以启用刷新 token