I've successfully get the code from square from OAuth authorization. But I can't exchange it to get the access token. I get this response:
{"message":"Missing required parameter `client_id`","type":"bad_request"}
My asp.net implementation is following:
object item = new { client_id = [app_id], client_secret = [app_secret], code = [authCode] };
JavaScriptSerializer serializer = new JavaScriptSerializer();
var json = serializer.Serialize(item);
HttpContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("https://connect.squareup.com");
AuthenticationHeaderValue auth = new AuthenticationHeaderValue("Authorization", "Client [app_secret]");
httpClient.DefaultRequestHeaders.Authorization = auth;
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Task<HttpResponseMessage> httpResponse = httpCLient.PostAsync("/oauth2/token", content);
if (httpResponse.Result.StatusCode != HttpStatusCode.OK)
{
}
string resultContent = httpResponse.Result.Content.ReadAsStringAsync().Result;
I got stuck at this point. Don't get why it says that client_id parameter is missing, though I send this parameter.
this solution solved the problem: