Azure-Samples / active-directory-dotnet-graphapi-web

A .NET 4.5 MVC web app that demonstrates how to query the Azure AD Graph API using the Azure AD Graph Client Library
82 stars 68 forks source link

How to obtain a directory extension #58

Open jbartolome opened 6 years ago

jbartolome commented 6 years ago

Hello, I'm trying to query a custom directory extension that was added to our user object in Azure AD. I'm able to get the property using the UserProfileController and updating the Model to have our custom extension property (see the two code snippets below).

Models/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; } }

View/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>
}

My goal is to have the extension extension_ExtId_ExtName appear on a list of users. I am trying to use the solution's UsersController and view to obtain this information, but it appears that the MS Graph API User model cannot be modified. The model is set to be of an IEnumerable for which the MS Graph Client contro. How do I add my custom extension so that I can retrieve it from the User object as well?

I've confirmed that I can obtain it via the user object by going to the Graph Explorer and setting my request URL to: https://graph.microsoft.com/beta/users('{user@email.com}')?select=extension_EXTENSION-ID_extensionName

Thanks