Skip to content

Instantly share code, notes, and snippets.

@rossigee
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossigee/2f2d628e22887e806f90 to your computer and use it in GitHub Desktop.
Save rossigee/2f2d628e22887e806f90 to your computer and use it in GitHub Desktop.
Checking/obtaining an OAuth2 session token w/CPD REST API v1
<?php
$params = array(
"client_id" => "683c5835a8d36a5bb974",
"client_secret" => "50ac9cb374989802d3d437c3fe0d7d8829c00e1b",
"username" => "user@theirdomain.co.uk",
"password" => "theirpasswordhere",
"grant_type" => "password",
);
$postData = "";
foreach($params as $k => $v) {
$postData .= $k . '='.urlencode($v).'&';
}
$postData = rtrim($postData, '&');
$url = "https://www.cpd.co.uk/restapi/v1/oauth2/access_token/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$rawdata = curl_exec($curl);
print $rawdata;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment