Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Just like here (users -> all users in the organization): 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. 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

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

like image 270
JhonBlack Avatar asked Jan 09 '18 14:01

JhonBlack


People also ask

How do I find my user ID for graph API?

You can get the user information for the signed-in user by replacing /users/{id | userPrincipalName} with /me .


1 Answers

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. For detailed comparison between them, you could follow Microsoft Graph or Azure AD Graph.

In general, Microsoft recommends you use Microsoft Graph over Azure AD Graph. I would recommend you use Microsoft Graph .NET Client Library to communicate with 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. For Azure AD v2.0, use the app registration portal, while for Azure AD v1.0, use portal.azure.com.

For Azure AD v2.0, you could follow this code sample for detailed steps. Moreover, you could also leverage Microsoft Authentication Library (MSAL) for acquiring the access token for constructing your 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:

enter image description here

Then, you could leverage ADAL for authenticating. Moreover, for detailed Microsoft Graph user permissions, you could follow here. For Delegated permissions vs Application permissions, you could follow here.

like image 76
Bruce Chen Avatar answered Oct 18 '22 01:10

Bruce Chen