Azure AD GraphServiceClient扩展不起作用 [英] Azure AD GraphServiceClient Extensions not working

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

问题描述

我有以下查询,用于使用具有.net core 2的GraphServiceClient检索用户.

I have the following query to retrieve a User using the GraphServiceClient with .net core 2.

 user = await _graphClient.Users[principalName].Request()
                    .Expand("Extensions")
                    .GetAsync();

运行此命令时,出现以下错误

When I run this I get the following error

Microsoft.Graph.ServiceException:代码:generalException消息: 服务意外返回异常.

Microsoft.Graph.ServiceException: Code: generalException Message: Unexpected exception returned from the service.

仅当我使用以下代码向用户添加了OpenTypeExtension时,才会发生这种情况!

This only happens when I have added a OpenTypeExtension to the user using the following code!

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);

我现在开始真的对Azure AD感到厌烦.

I am starting to get really getting fed up with Azure AD now.

我似乎无法向用户添加任何元数据.仅这样做是因为otherEmailsGraphServiceClient不兼容,并且尝试使用任何其他明智的字段都会给我以下错误:

I can't seem to add any meta data to my users. Only doing this because otherEmails does not work with the GraphServiceClient and trying to use any other sensible fields gives me this error:

租户在更新用户时没有SPO许可证

Tenant does not have a SPO license when updating user

任何帮助将不胜感激.

Any help would be appreciated.

推荐答案

因此,对于遇到此问题的任何其他人,这似乎是服务客户端中的错误.

So for anyone else that come across this, it seems to be an a bug in the service client.

下面的代码失败

  user = await _graphClient
                    .Users[userId]
                    .Request()
                    .Expand("Extensions")
                    .GetAsync();

但是此代码有效,仅在单独的调用中请求扩展即可!

But this code works, just by requesting the extensions in a separate call!

 user = await _graphClient
                    .Users[userId]
                    .Request()
                    .GetAsync();

                var extensions = await _graphClient.Users[user.Id].Extensions.Request().GetAsync();
                user.Extensions = extensions;

希望我在此上浪费的时间可以节省一个人!

Hope that save's someone the time I lost on this!

这篇关于Azure AD GraphServiceClient扩展不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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