In the previous post you see how register your API app in the AAD and how register a client app to then access using RESTful AAD api. The work to do to access your API is not so much using any langue, btw is even more easy using .NET.
Creates a new Console project and then add Microsoft.IdentityModel.Clients.ActiveDirectory package.
Now add this class to your project
We will use the implementation of HttpMessageHandler for the pipeline of the instance of HttpClient we will use to access to our API.
The HtppMessageHandler needs three parameters: AuthenticationContext, ClientCredential and appIDUri. To create each one we needs some information we have seen in the previous post and to be consistent I will reuse the same images.
To create an instance of the AuthenticationContext we need only the URL of the AAD where our API-app and our client are registered. It should look something like this:
To create an instance of ClientCredential we need the “Application ID” and the “Key” of our client registered un our AAD:
the Application ID is
the key is
The App ID URI is the value we give to our API-app registered in our AAD
The usage of ActiveDirectoryAuthHandler
Just remember that the instance of the HttpClient should be a singleton with the same lifecycle of your application.