【问题标题】:Unable to update the specified properties for on-premises mastered Directory Sync objects or objects currently undergoing migration无法更新本地主控目录同步对象或当前正在迁移的对象的指定属性
【发布时间】:2016-10-19 17:14:07
【问题描述】:

在 Azure AD 中将成员添加到组时出现问题,收到此错误消息:

无法更新本地主控的指定属性 目录同步对象或当前正在迁移的对象

我正在尝试将 azure AD 的现有成员添加到现有组,但我收到“错误请求”的响应。对于某些调用 updateasync 工作正常,但成员未添加到组中。我已经提供了我正在尝试解决以下错误的代码。请建议是否有人遇到过同样的问题并解决它。谢谢。

代码:-

 IUser newUser = await GetUser(userKey);
                Microsoft.Azure.ActiveDirectory.GraphClient.Group retrievedGroup = new Microsoft.Azure.ActiveDirectory.GraphClient.Group();
                List<IGroup> foundGroups = null;
                foundGroups = adClient.Groups
                         .Where(group => group.DisplayName.StartsWith(groupName))
                         .ExecuteAsync().Result.CurrentPage.ToList();
                if (foundGroups != null && foundGroups.Count > 0)
                {
                    retrievedGroup = foundGroups.First() as Microsoft.Azure.ActiveDirectory.GraphClient.Group;
                }
                if (retrievedGroup.ObjectId != null)
                {
                    retrievedGroup.Members.Add(newUser as DirectoryObject);
                    await retrievedGroup.UpdateAsync();
                }

错误:-

{"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"Unable to update the specified properties for on-premises mastered Directory Sync objects or objects currently undergoing migration."},"date":"2016-10-18T08:02:22","requestId":"c757689c-6135-4198-9e4d-6a7aaa1135e7","values":null}}

【问题讨论】:

    标签: asp.net asp.net-web-api azure-ad-graph-api


    【解决方案1】:

    根据描述和错误消息,您使用 Azure Graph 客户端将成员添加到在本地创建的组中。这是意料之中的,它无法更新从本地同步到 Azure AD 的这些对象。

    要为此类群组添加成员,我们需要在本地环境中对其进行操作,然后将其同步到 Azure。

    更新

    使用 Azure AD Graph 客户端创建组并添加成员:

    var client = GraphHelper.CreateGraphClient();
    
    var group = new Microsoft.Azure.ActiveDirectory.GraphClient.Group();
    group.DisplayName = "newGroup";
    group.MailNickname = "newGroup";
    group.MailEnabled = false;
    group.SecurityEnabled = true;
    await client.Groups.AddGroupAsync(group);
    
    var newGroup = client.Groups.ExecuteAsync().Result.CurrentPage.First(a => a.DisplayName == "newGroup") as Microsoft.Azure.ActiveDirectory.GraphClient.Group;
    
    var user = client.Users.ExecuteAsync().Result.CurrentPage.First(u => u.DisplayName == "user2") as Microsoft.Azure.ActiveDirectory.GraphClient.DirectoryObject;
    
    group.Members.Add(user);
    await group.UpdateAsync();
    
    
    public static ActiveDirectoryClient CreateGraphClient()
    {
            string accessToken = "";
            string tenantId = "xxx.onmicrosoft.com"; 
            string graphResourceId = "https://graph.windows.net";
    
            Uri servicePointUri = new Uri(graphResourceId);
            Uri serviceRoot = new Uri(servicePointUri, tenantId);
    
            ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, async () => await Task.FromResult(accessToken));
    
            return activeDirectoryClient;
    }
    

    【讨论】:

    • 嗨飞,谢谢你的评论,你说graph API只能更新直接在Azure AD上创建的用户吗?想知道除了图形 API 是否有任何替代方案,或者我可以使用图形 API 创建组并将用户分配给它吗?请提出建议。
    • 是的。图形 API 只能更新在 Azure AD 上创建的对象。是的,Graph API 可以创建组和分配用户,您可以参考它的详细信息here。我还使用 Azure Graph 客户端编写了一个代码示例来创建一个组并将成员添加到该组中。
    • 非常感谢您的宝贵回答。我已通过图形 API 创建了一个群组并成功将用户添加到该群组。但需要为在本地创建并与之同步的群组寻找解决方案Azure AD。
    猜你喜欢
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    相关资源
    最近更新 更多