Link to home
Start Free TrialLog in
Avatar of romanm
romanm

asked on

How to authenticate user credentials on Azure Active Directory without invoking the microsoft login UI?

I have username and password,
I'd like to authenticate these with the Azure Active Directory in my cloud, and I want it to be done with Microsoft Graph API if possible.
And most important, absolutely no user interface. Assume its all running via command line, or in a script.

So far I got the UI way (using C# but ultimately it will be C++):

Uri authUri = new Uri(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/authorize", TenantId));
try
{
   string data = string.Format("client_id={0}&response_type=code&response_mode=query&scope=user.read&redirect_uri={1}", ClientId, WebUtility.UrlEncode(redirectUrl));
   BrowsePage b = new BrowsePage();
   b.navigate(authUri, data);
   b.Show();

   b.Closed += new EventHandler((object sender, System.EventArgs e) =>
   {
      is_authenticated = true;
   });
}
catch (System.Net.WebException ex)
{
    System.Console.WriteLine("Authorize request: " + ex.Message);
}
ASKER CERTIFIED SOLUTION
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of romanm
romanm

ASKER

Thanks, I'm building a proxy authentication server that performs this. So there is no actual user to handle UI queries.
What I really want to find out are the internals of those methods, at least for this user credentials scenario.
Well I'm no programmer so I cannot give you that many details, but the ADAL source code is available on GitHub, so just find the AcquireTokenAsync method and check the logic used therein.
Avatar of romanm

ASKER

ADAL doesn't work for me, tried AuthenticationContextIntegratedAuthExtensions but it returns an error that the query is missing the client_secret or client_assertion.

basically the use case I'm trying to solve is like this,
the server gets a request to authenticate a user, identified by a retina scan and finger print,
the server after processing the data pulls from a database:
  1. username
  2. password
  3. app id
  4. app secret
  5. app uri
with these 5 the server would call the AAD to authenticate the user, and get the user permissions.
this all happens with no UI.

And try as I may, nothing actually works.
Avatar of romanm

ASKER

Thanks for the effort.