Azure ADのユーザーオブジェクトに追加されたカスタムディレクトリ拡張を照会しようとしています。私は見つけた解決策を使用していますhere。MSグラフを使用してAzure ADでディレクトリ拡張を取得する方法
UserProfileControllerを使用してプロパティを取得し、カスタム拡張プロパティを持つようにモデルを更新できます(下記の2つのコードスニペットを参照)。
モデル/ 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モデルを変更できないようです。モデルは、Microsoft Graph Clientが制御するIEnumerable<User>
に設定されています。
カスタムエクステンションを追加して、それをUserオブジェクトからも取得できるようにするにはどうすればよいですか?私はグラフエクスプローラに行くとに私の要求のURLを設定することで、ユーザオブジェクトを介して取得できることが確認できました
:
https://graph.microsoft.com/beta/users('{[email protected]}')?select=extension_EXTENSION-ID_extensionName
おかげで
を他の部分がAzure AD Graph APIを参照するのに対して、その一部はMS Graph APIを参照するため、私のコードを見直しました。私は自分のプロジェクトでMS Graph APIを使いたいので、この分野に焦点を当てます。自分のUserProfileControllerがMS Graphに依存し、UserControllerがAzure ADに依存していることに気付きました。ありがとうございました。 –
私は 'aspnet-snippets-example'を使って美しく動作させようとしましたが、前に投稿したグラフのURLに示すようにカスタムディレクトリ拡張を取得しようとしていません。再度、ディレクトリ拡張を含むようにソリューションのViewModelを更新しようとしましたが、Graph Userオブジェクトを参照しているため、まだ取得できませんでした。助けて? –
私はあなたが['User'](' https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/src/Microsoft.Graph/Models/Generated 'の 'Extensions'プロパティを探していると思います/User.cs)。 –