Skip to content

Instantly share code, notes, and snippets.

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 angarsky/a0810a230b467b82ab2ffcde1e808a54 to your computer and use it in GitHub Desktop.
Save angarsky/a0810a230b467b82ab2ffcde1e808a54 to your computer and use it in GitHub Desktop.
$client_id = '';
$client_secret = '';
$endpoint = "http://site.dev";
$curl = curl_init($endpoint . '/oauth2/token');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$params = array(
"client_id" => $client_id,
"client_secret" => $client_secret,
"grant_type" => "client_credentials",
);
$postData = "";
foreach($params as $k => $v) {
$postData .= $k . '='.urlencode($v).'&';
}
$postData = rtrim($postData, '&');
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
print curl_error($curl);
}
curl_close($curl);
print $json_response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment