Azure AD GraphServiceClient无法针对用户设置AdditionalData [英] Azure AD GraphServiceClient can't set AdditionalData against User

查看:31
本文介绍了Azure AD GraphServiceClient无法针对用户设置AdditionalData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将GraphServiceClient与.Net Core 2配合使用.我正在尝试使用以下代码向我的用户添加AdditionalData

I am using the GraphServiceClient with .Net Core 2. I am trying to add AdditionalData to my Users using the following code

var updated = new User()
                {
                   AdditionalData = new Dictionary<string, object>
                    {
                        {"OtherEmail", otherEmail},
                        {"OtherRole", otherRole}
                    },
                };

                await _graphClient.Users[user.Id].Request().UpdateAsync(updated);

执行此操作时,出现以下错误

When this executes I get the following error

Microsoft.Graph.ServiceException:代码:Request_BadRequest消息:指定的一个或多个属性值无效.

Microsoft.Graph.ServiceException : Code: Request_BadRequest Message: One or more property values specified are invalid.

有人知道我在做什么错吗?

Does anyone know what I am doing wrong ?

如果有人可以告诉我如何将自己的一些元数据保存给用户,将不胜感激.我也尝试过使用扩展程序,但是我遇到了这个问题.

Also if anyone can please tell me how I can just save some of my own metadata against a user it would be really appreciated. I have also tried using the extensions, but I am having this problem.

Azure AD GraphServiceClient扩展不起作用

推荐答案

所以我使用OpenExtensions解决了这个问题,这也给我带来了很多问题,可以在这里看到.

So I got around this using OpenExtensions, this also caused me a lot of issues, which can be seen here.

Azure AD GraphServiceClient扩展不起作用

技巧是添加这样的扩展名

Trick is to add the extensions like this

extension = new OpenTypeExtension
                {
                    ExtensionName = AzureADExtensions.UserConstants.ExtensionName,
                    AdditionalData = new Dictionary<string, object>
                    {
                        {"OtherEmail", externalUser.Email},
                        {"OtherRole" , externalUser.Roles.FirstOrDefault()}
                    }
                };

                await _graphClient.Users[user.Id].Extensions.Request()
                    .AddAsync(extension);

然后像这样检索它们.

user = await _graphClient
                    .Users[userId]
                    .Request()
                    .GetAsync();
// Note : you should be able to expand this on original request, but fails for me.
                var extensions = await _graphClient.Users[user.Id].Extensions.Request().GetAsync();
                user.Extensions = extensions;

希望对某人有帮助!

这篇关于Azure AD GraphServiceClient无法针对用户设置AdditionalData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆