MVC5 How can I retrieve all users from Azure Active Directory

余生长醉 提交于 2019-12-12 04:35:12

问题


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.



来源:https://stackoverflow.com/questions/41816258/mvc5-how-can-i-retrieve-all-users-from-azure-active-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!