'Simplicity is the ultimate sophistication' - Leonardo da Vinci



(HRQ) ADAL and Console Applications

Here is the example console code from the video:

using System;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks;

namespace ADALConsole
        class Program
        static void Main(string[] args)
        static async Task CallWebApiWithADALAsync(string restEndpoint)
            string resource = "https://[...]";

            //App Registered in Tenant AADols
            string clientId = "57c1af48-[...]";

            string redirectUrl = "";
            string authority = "";

            PlatformParameters parameters = new PlatformParameters(PromptBehavior.RefreshSession);
                AuthenticationContext authContext = new AuthenticationContext(authority);
                var token = await authContext.AcquireTokenAsync(resource, clientId, new Uri(redirectUrl), parameters);
                var authHeader = token.CreateAuthorizationHeader();
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(token.AccessTokenType, token.AccessToken);
                Uri requestURI = new Uri(restEndpoint);
                Console.WriteLine($"Calling REST API:'{requestURI}'.");
                HttpResponseMessage httpResponse = await client.GetAsync(requestURI);
                Console.WriteLine($"HTTP Code: '{httpResponse.StatusCode.ToString()}'");
                string response= await httpResponse.Content.ReadAsStringAsync();
                var json = JsonConvert.DeserializeObject(response);
                Console.WriteLine($"Response: {json}");
            catch (Exception ex)
                Console.WriteLine("Exception Message: " + ex.Message);
                Console.WriteLine("Stack: " + ex.StackTrace);

Edit 10/12/2017: At 4m 09s, I am mention the Authority. The authority,  or authorization server, gets consent form the resource owner and issues the client token.

steve kurtz