Microsoft Graph API : User Management in Azure AD with .NET Core

Rohit Bhilare
3 min readJul 25, 2020

--

https://gxcuf89792.i.lithium.com/t5/image/serverpage/image-id/86459i691A5DADF8A7B2C8/image-size/large?v=1.0&px=999
Flow of Graph API

Hello All ✋ ,
I am pretty new to Azure DevOps account and trying to build this API with some research as I haven't found any reference for REST API, all available recourse is for MVC only😒 .

What is Graph API ?

Microsoft Graph is a RESTful web API that enables you to access Microsoft Cloud service resources. After you register your app and get authentication tokens for a user or service, you can make requests to the Microsoft Graph API.[refer]

Configure Azure AD account

  1. Login to Microsoft Azure Portal and Go to Active directory service and find your Tenant information (eg. Tenant ID and Primary Domain).
  2. Next step is to Register app : (Left panel you will find App registration). Click on new registration
App registration

3. After registration Go inside of the App and find API permissions. Click add permission > Graph > Add below list of permission

4. Next is to create client secret key; Click on Certificate & secrets > New client certificate > provide description and any expiration time. After add, copy secret value for further use.

Lets Start with Coding

  1. Create a new .net core project with rest API.
  2. Add following data to your appsetting.json file to connect your Azure registered app with Dotnet Application.

3. Create a new folder in App (named Service) and create new GraphClient.cs for configuring graph API.

GraphClient service use to config your app with Azure account setting provided in appsetting.json; Also used to get all Graph Endpoints with use of GetserviceClient function . Authprovider function creates a bearer token on every request to API to authenticate the Account.

4. We require 2 Model first is UserModel and second is ADConfigModel

5. Datahandler is service used to manipulate data coming from the request

6. Create UserController to control to manage API request.(Suggested : Delete all other default controllers)

Get request to get all users from the account

Post request to add user in AD account

Thank You for reading this blog. I hope this helps you.

Reference

Microsoft Graph API
Play with Graph Explorer
Source Code:

--

--