I am attempting to get data from https://[org uri].crm.dynamics.com/api/data/v9.1/aadusers.
Docs here: https://learn.microsoft.com/sr-cyrl-rs/power-apps/developer/data-platform/aaduser-entity
If I am logged in to my Microsoft account and go to the URL, I get back the correct data from the API. If I am not logged in, I get a http 401 response which makes sense.
I am working on a .NET app and want the app to be able to get and parse the resulting data.
How can my app 'login' to Microsoft to make the GET request?
I tried adding a basic auth header to the request, no luck.
I then tried:
var credentials = new NetworkCredential("username", "password");
var handler = new HttpClientHandler { Credentials = credentials };
using (var http = new HttpClient(handler))
{
http.GetAsync("https://[org uri].crm.dynamics.com/api/data/v9.1/aadusers");
}
which also returned a http 401.
After more googling, Ii found exactly what I was looking for.
https://learn.microsoft.com/en-us/graph/tutorials/dotnet-app-only