Created
May 29, 2017 10:32
-
-
Save angarsky/a0810a230b467b82ab2ffcde1e808a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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