MVC5 How can I retrieve all users from Azure Activ

2019-09-11 08:17发布

问题:

Hi I'm relatively new to Azure. I want to create a dropdownlist that contains all the user's display name from the Azure's Active Directory but I'm not sure how to do it.

I briefly looked at the graph API from https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations but I don't know how to call it in MVC nor getting the JSON data that contains the display name.

Any help or code example will be appreciated

回答1:

You could get started using this Azure AD sample https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web, look at the WebAppGraphAPI/Controllers/UsersController.cs class, it does pretty much what you are looking for.

The code from the sample uses the SDK (found in the NuGet package Microsoft.IdentityModel.Clients.ActiveDirectory) and you get an object model for the graph results, not a JSON string. If you absolutely want to use the REST API then you could (https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers) but the SDK should be much more convenient for you since you can easily add the NuGet.

Side note, you will need to register your application with the Azure AD in the portal and you need admin rights to do that.