As specified in the Authorization Code Flow tutorial at
https://developer.blackbaud.com/skyapi/docs/authorization/auth-code-flow/tutorial, I make an authorization request by building out this URL with the correct parameters and then redirecting to that URL:
var url = "https://oauth2.sky.blackbaud.com/authorization?" + "client_id=" + ConfigurationManager.AppSettings["AuthClientId"] + "&response_type=code" + "&redirect_uri=" + ConfigurationManager.AppSettings["AuthRedirectUri"] + "&state=" + ConfigurationManager.AppSettings["AuthState"]; Response.Redirect(url);That works, no problem. I'm redirected back to my application with a new "code" parameter. I then use that value to request an access token. Here is the function I use:
void GetToken(string code) { var client = new System.Net.Http.HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); var auth = Base64Encode(ConfigurationManager.AppSettings["AuthClientId"]) + ":" + Base64Encode(ConfigurationManager.AppSettings["AuthClientSecret"]); // Request headers client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", auth); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); // Query string parameters queryString["grant_type"] = "authorization_code"; queryString["code"] = code; queryString["redirect_uri"] = ConfigurationManager.AppSettings["AuthRedirectUri"]; var uri = "https://oauth2.sky.blackbaud.com/token?" + queryString; var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("","") }); var response = client.PostAsync(new Uri(uri), content).Result; ConfigurationManager.AppSettings["AuthToken"] = response.ToString(); }The problem is, I get this response:
StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{ X-Frame-Options: DENY Cache-Control: private Date: Wed, 12 Aug 2020 19:40:47 GMT Set-Cookie: visid_incap_855125=R7lFdEGuTI2H1S1GfQTzLL9FNF8AAAAAQUIPAAAAAACeEyJb6hFOtWK0u/dskR+5; expires=Thu, 12 Aug 2021 13:30:00 GMT; HttpOnly; path=/; Domain=.sky.blackbaud.com Set-Cookie: incap_ses_541_855125=dSJWTUF7C1XOXLcgzASCB79FNF8AAAAAcQzkcWKAMMyJUo0BaCXRNg==; path=/; Domain=.sky.blackbaud.com X-CDN: Incapsula X-Iinfo: 10-2995024-2995029 NNNN CT(58 140 0) RT(1597261247237 73) q(0 0 2 -1) r(2 3) U5 Content-Length: 3420 Content-Type: text/html; charset=utf-8}What am I doing wrong? Can anyone help?