Created
November 26, 2018 02:25
-
-
Save olafloogman/f11d53ea469e71e7940568a6db9de4aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
HttpClient client = new HttpClient(); | |
// STS | |
string cloud = "https://login.microsoftonline.com"; | |
string tenantId = "e0e04c7d-4d23-4078-9562-cea9be7bffed"; | |
string authority = $"{cloud}/{tenantId}"; | |
// Application | |
string clientId = "ed97e261-0f45-4123-33921-e5f6119da09c"; | |
string appKey = "eR9klLZqNJwTzew4NYeEL/nfVv8HaqOP67MrFRpihwB="; | |
Uri redirectUri = new Uri("http://localhost"); | |
// Application ID of the Resource (could also be the Resource URI) | |
string resource = "b4439d32-e7b0-124d-9858-a18ea2ccee99"; | |
var clientCredential = new ClientCredential(clientId, appKey); | |
AuthenticationContext ac = new AuthenticationContext(authority); | |
AuthenticationResult result = ac.AcquireTokenAsync(resource, clientCredential).Result; | |
client.BaseAddress = new Uri("https://kloud.azure-api.net"); | |
client.DefaultRequestHeaders.Accept.Clear(); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); | |
try | |
{ | |
var apiResult = client.GetStringAsync("/simpleecho/echo").Result; | |
Console.WriteLine(apiResult); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex); | |
} | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment