Get list of users on Azure Active Directory using Microsoft Graph API
Documentation Links:
- Obtain a valid authentication token:
-
Navigate to
Azure Active Directory
-
Create a new
App registration
-
Add
API Permissions
for the Graph resources you’d like to access-
Click on the newly created application
-
Add the following permissions
-
Click on
Add a permission
-
Navigate to
Microsoft APIs
->Microsoft Graph
->Application permissions
-
Search for
User
-
Click
User.Read.All
andUser.ReadBasic.All
-
Navigate to
Microsoft APIs
->Microsoft Graph
->Delegate permissions
-
Search
User
-
Click on
User.Read
andUser.ReadBasic.All
->Add Permission
-
Make sure to click
Grant admin consent
-
- Creating application
-
Navigate to
Certificates & Secrets
and create aNew client secrets
-
Copy the
Value
and paste it into notepad -
Go back to
Overview
-
Copy
Application (client) ID
as well asDirectory (tenant) ID
and paste them into notepad -
Go to this GitHub repository to find the code:
https://github.com/omoinjm/azure-user-list
OR
-
Create new Console Application:
dotnet new console
-
Install the following packages:
dotnet add package DotNetEnv dotnet add package Microsoft.Graph.Auth --version 1.0.0-preview.7 dotnet add package Microsoft.Graph dotnet add package Microsoft.Identity.Client
-
Insert code in Program.cs
-
Insert Environment Variables