我试图查询添加到Azure AD中的用户对象的自定义目录扩展。我正在使用找到的解决方案here。如何使用MS Graph在Azure AD中获取目录扩展
我能够使用UserProfileController获取属性并更新模型以具有我们的自定义扩展属性(请参阅下面的两个代码片段)。
型号/ UserProfile.cs
public class UserProfile
{
public string DisplayName { get; set; }
public string GivenName { get; set; }
public string Surname { get; set; }
public string extension_ExtId_ExtName { get; set; }
}
查看/ UserProfile.cshtml
@model App.Models.UserProfile
<h2>@ViewBag.Title.</h2>
<table class="table table-bordered table-striped">
<tr>
<td>Display Name</td>
<td>@Model.DisplayName</td>
</tr>
<tr>
<td>First Name</td>
<td>@Model.GivenName</td>
</tr>
<tr>
<td>Last Name</td>
<td>@Model.Surname</td>
</tr>
<tr>
<td>Employee Id</td>
<td>@Model.extension_ExtId_ExtName</td>
</tr>
</table>
@if (ViewBag.ErrorMessage == "AuthorizationRequired")
{
<p>You have to sign-in to see your profile. Click @Html.ActionLink("here", "Index", "UserProfile", new { reauth = true }, null) to sign-in.</p>
}
@if (ViewBag.ErrorMessage == "UnexpectedError")
{
<p>An unexpected error occurred while retrieving your profile. Please try again. You may need to sign-in.</p>
}
我的目标是具有扩展extension_ExtId_ExtName
出现用户的列表上。我试图使用解决方案的UsersController
并查看以获取此信息,但似乎无法修改Microsoft Graph API User模型。该模型设置为IEnumerable<User>
,其中Microsoft Graph客户端控件。
如何添加我的自定义扩展,以便我可以从User对象中检索它?
我证实,我可以将图形Explorer和我的请求的URL设置为通过用户对象获得它:
https://graph.microsoft.com/beta/users('{[email protected]}')?select=extension_EXTENSION-ID_extensionName
感谢
我明白你说什么,我现在检查我的代码,因为它的一部分引用了MS Graph API,而另一部分引用了Azure AD Graph API。我更喜欢在我的项目中使用MS Graph API,因此我将专注于此领域。我意识到我的UserProfileController依赖于MS Graph,而UserController依赖于Azure AD。谢谢。 –
好吧,我试图使用'aspnet-snippets-example'并使其工作得很好,但是现在我反对试图拉取自定义目录扩展名,如前面发布的图形URL中所示。再次,我尝试更新ViewModel,以包含目录扩展的解决方案,但我仍然无法获得它,因为它引用了图形用户对象。帮帮我? –
我相信你正在寻找['User']的'Extensions'属性(https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/src/Microsoft.Graph/Models/Generated /User.cs)。 –