Created
May 23, 2020 09:11
-
-
Save manoj-choudhari-git/5ed9f94373720526a59e9fbac8f781e8 to your computer and use it in GitHub Desktop.
Code to call the caller-api
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
//// Acquire the access token. | |
string[] scopes = new string[] { "user.read", "api://5e999e55-a661-4982-b897-965480492129/access_as_user", "api://262f3e7b-20cb-42cb-8a23-2d6c8003ee3a/caller-api" }; | |
string accessToken = await _tokenAcquisition.GetAccessTokenForUserAsync(scopes); | |
//// API URL | |
string url = "https://localhost:44370/weatherforecast"; | |
HttpClient client = new HttpClient(); | |
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); | |
string json = await client.GetStringAsync(url); | |
var apiOutput = JsonConvert.DeserializeObject<List<WeatherForecast>>(json); | |
ViewData["ApiOutput"] = apiOutput; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment