OAUTH - Not getting back authorization token
Perhaps someone in this forum can help answer this question. There aren't any OAuth exampels for PHP.
My code is failing on the last ajax call to the OAuth API. I am getting a NULL response from Wild Apricot.
Perhap someone can let me know what is wrong withthis code:
$credentials = '[client_id]:[secret]';
//extract data from the post
//set POST variables
$url = 'http://oauth.wildapricot.org/auth/token';
$fields = array(
'grant_type' => "authorization_code",
'code' => CCGetParam("code",0),
'client_id' => '[client_id]',
'redirect_uri' => "https://[domain.com]/login2.php",
'scope' => 'contacts_me'
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string, '&');
//open connection
$ch = curl_init();
$headers = array(
'Authorization: Basic '. base64_encode($credentials)
);
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
// Will return the response, if false it prints the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
===
-
code_sponge commented
Creating this coding is not my strength, but finding simple errors that break stuff I'm good at as I hack my way through. So I ask you, in the following line of code, is it supposed to uri or url?
'redirect_uri' => "https://[domain.com]/login2.php",