Skip to content

Instantly share code, notes, and snippets.

@angarsky
Created May 29, 2017 10:37
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/9f43e9fcccfc7fbb3a8242fedc6fe03e to your computer and use it in GitHub Desktop.
Save angarsky/9f43e9fcccfc7fbb3a8242fedc6fe03e to your computer and use it in GitHub Desktop.
Example of code to make an API call with Access Token
$client_id = '';
$client_secret = '';
$endpoint = "http://site.dev";
if (!isset($_GET['access_token'])) {
print 'Access token is not define.';
die;
}
$curl = curl_init($endpoint . '/api/sso/v0.1/user/profile');
$data = '{"username":"my@mail.dev"}';
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data),
'Authorization: Bearer ' . $_GET['access_token']
)
);
try {
$output = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
} catch (Exception $e) {
$output = $e->getMessage();
}
curl_close($curl);
echo $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment