Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 23, 2020 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/fce542b0c2abbc68e8fb095ca2cbed4b to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/fce542b0c2abbc68e8fb095ca2cbed4b to your computer and use it in GitHub Desktop.
Code to call caller API successfully
//// 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