OAuth2 returns invalid_client error
The problem is in the cURL headers you're setting something.php
. Remove the Content-Type
header. In fact, you can not set the headers at all - cURL will send the correctly encoded parameters and Box will return JSON data by default.
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: application/json'));
Here is how I received the token in JS
authorizeUser = function(){ var results = $.ajax({ // The URL to process the request url : 'https://www.box.com/api/oauth2/token', type : 'POST', data : { grant_type : 'authorization_code', code : data.boxAuthorizationCode, client_id : data.clientId, client_secret : data.clientSecret }, beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", "Bearer $token")}, dataType: "json", success: function(response) { //console.log(response); console.log(response.access_token); data.access_token = response.access_token; tokenGranted(); } }); return results.responseText; },