Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 23, 2020 09:11
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/5ed9f94373720526a59e9fbac8f781e8 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/5ed9f94373720526a59e9fbac8f781e8 to your computer and use it in GitHub Desktop.
Code to call the caller-api
//// 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