Is it possible to use AzureAD authentication with a console application?
.net, azure, azure-active-directory, console-application
Solution
In fact, any client application should be regsitered in AAD.
Console app must be registered in Azure AD too, so you'll have client id and client redirect url, but no client secret. Then the following code should work:
void Main()
{
var clientId = "client-GUID";
var clientUrl = new Uri("redirect-url"); //can be anything starting with localhost
var tenant = "name of your AAD tenant";
string authority = "https://login.windows.net/" + tenant;
string resource = "https://outlook.office365.com"; ///put id or url of resource you're accessing
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
Console.WriteLine("Trying to acquire token");
var pp = new PlatformParameters(PromptBehavior.Auto); //this brings web prompt
var token = authenticationContext.AcquireTokenAsync(resource, clientId, clientUrl, pp, UserIdentifier.AnyUser).Result;
Console.WriteLine("Got the token: {0}", token.AccessToken);
}
Problem
The idea is to make it work like Azure Powershell, i.e. the standard Active Directory authentication dialog pops up, I enter my credentials, AzureAD does its thing and then the console application cann access a certain webservice. Is this possible? It shouldn't be that hard but I could find no example. Looking at the WPF example, I see it sets a client id in the app.config. Is this really necessary? I mean, a single page js app isn't registered with the AD either, is it?