简体   繁体   English

图谱API从Azure AD获取用户

[英]Graph API get users from Azure AD

I have users in my Azure AD, i need to get users from AD and put it in C# list with all their properties. 我的Azure AD中有用户,我需要从AD获取用户并将其放在C#列表中,并包含其所有属性。 Just like here ( users -> all users in the organization ): https://developer.microsoft.com/en-us/graph/graph-explorer# 就像这里( 用户 - >组织中的所有用户 ): https//developer.microsoft.com/en-us/graph/graph-explorer#

I found some documentation but i dont understand how to use it properly. 我找到了一些文档,但我不明白如何正确使用它。 In general, result must be C# list, or maybe json file with users and their properties. 通常,结果必须是C#list,或者可能是带有用户及其属性的json文件。 Can you please give me an example or something? 你能给我一个例子吗?

Documentation: 文档:

  1. https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers

  2. https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureaduser?view=azureadps-2.0 https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureaduser?view=azureadps-2.0

https://developer.microsoft.com/en-us/graph/graph-explorer is talking about Microsoft Graph API, while https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers is talking about Azure AD Graph API. https://developer.microsoft.com/en-us/graph/graph-explorer正在谈论Microsoft Graph API,而https://msdn.microsoft.com/en-us/library/azure/ad/graph/api / users-operations#GetUsers正在讨论Azure AD Graph API。 For detailed comparison between them, you could follow Microsoft Graph or Azure AD Graph . 有关它们之间的详细比较,您可以按照Microsoft Graph或Azure AD Graph进行操作

In general, Microsoft recommends you use Microsoft Graph over Azure AD Graph. 通常,Microsoft建议您使用Microsoft Graph over Azure AD Graph。 I would recommend you use Microsoft Graph .NET Client Library to communicate with Microsoft Graph API. 我建议您使用Microsoft Graph .NET Client Library与Microsoft Graph API进行通信。

In order to authenticate for the Microsoft Graph service, firstly you need to register your application to use the Microsoft Graph API. 要对Microsoft Graph服务进行身份验证,首先需要注册您的应用程序以使用Microsoft Graph API。 For Azure AD v2.0, use the app registration portal , while for Azure AD v1.0, use portal.azure.com . 对于Azure AD v2.0,请使用应用程序注册门户 ,而对于Azure AD v1.0,请使用portal.azure.com

For Azure AD v2.0, you could follow this code sample for detailed steps. 对于Azure AD v2.0,您可以按照此代码示例获取详细步骤。 Moreover, you could also leverage Microsoft Authentication Library (MSAL) for acquiring the access token for constructing your GraphServiceClient . 此外,您还可以利用Microsoft身份验证库(MSAL)获取用于构建GraphServiceClient的访问令牌。

For Azure AD v1.0, you need to register your app and grant the permissions for your app to access Microsoft Graph API as follows: 对于Azure AD v1.0,您需要注册您的应用并授予您的应用访问Microsoft Graph API的权限,如下所示:

在此输入图像描述

Then, you could leverage ADAL for authenticating. 然后,您可以利用ADAL进行身份验证。 Moreover, for detailed Microsoft Graph user permissions, you could follow here . 此外,对于详细的Microsoft Graph用户权限,您可以按照此处操作 For Delegated permissions vs Application permissions, you could follow here . 对于委派权限与应用程序权限,您可以按照此处操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM