MVC5如何从Azure Active Directory检索所有用户 [英] MVC5 How can I retrieve all users from Azure Active Directory
问题描述
我对Azure比较陌生.我想创建一个下拉列表,其中包含Azure的Active Directory中所有用户的显示名称,但是我不确定该怎么做.
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.
我从 https://msdn.microsoft.com/zh-CN/library/azure/ad/graph/api/users-operations ,但我不知道如何在MVC中调用它,也不知道如何获取包含显示名称.
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
推荐答案
您可以开始使用此Azure AD示例 WebAppGraphAPI/Controllers/UsersController.cs
类,它几乎可以完成您的工作正在寻找.
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.
样本中的代码使用SDK(位于NuGet包Microsoft.IdentityModel.Clients.ActiveDirectory
中),您将获得图形结果的对象模型,而不是JSON字符串.如果您绝对要使用REST API,则可以( https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers ),但SDK将会为您带来更多便利您可以轻松添加NuGet.
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.
旁注,您将需要在门户中的Azure AD中注册您的应用程序,并且需要管理员权限.
这篇关于MVC5如何从Azure Active Directory检索所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!