in OAuthWebSample/OAuthWebSample/Controllers/OAuthController.cs [65:109]
public async Task<ActionResult> Callback(String code, Guid state)
{
String error;
if (ValidateCallbackValues(code, state.ToString(), out error))
{
// Exchange the auth code for an access token and refresh token
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, ConfigurationManager.AppSettings["TokenUrl"]);
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Dictionary<String, String> form = new Dictionary<String, String>()
{
{ "client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" },
{ "client_assertion", ConfigurationManager.AppSettings["ClientAppSecret"] },
{ "grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer" },
{ "assertion", code },
{ "redirect_uri", ConfigurationManager.AppSettings["CallbackUrl"] }
};
requestMessage.Content = new FormUrlEncodedContent(form);
HttpResponseMessage responseMessage = await s_httpClient.SendAsync(requestMessage);
if (responseMessage.IsSuccessStatusCode)
{
String body = await responseMessage.Content.ReadAsStringAsync();
TokenModel tokenModel = s_authorizationRequests[state];
JsonConvert.PopulateObject(body, tokenModel);
ViewBag.Token = tokenModel;
}
else
{
error = responseMessage.ReasonPhrase;
}
}
if (!String.IsNullOrEmpty(error))
{
ViewBag.Error = error;
}
ViewBag.ProfileUrl = ConfigurationManager.AppSettings["ProfileUrl"];
return View("TokenView");
}