Created
May 23, 2020 09:13
-
-
Save manoj-choudhari-git/fce542b0c2abbc68e8fb095ca2cbed4b to your computer and use it in GitHub Desktop.
Code to call caller API successfully
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://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