Commit b7b03994 authored by Tariq Khan's avatar Tariq Khan 💬

Update oauth2.php

parent 45ef4c54
......@@ -22,6 +22,8 @@ class Oauth2 {
elseif(isset($_GET['refreshToken'])) $this->refreshAccessToken(true);
elseif(isset($_GET['entries'])) $this->getTrackingDeviceEntries($_GET['entries']);
if($this->isUserAuthenticated()) $this->fetchAllDevices();
// Use the following function to test response data for a give endpoint
//if($this->isUserAuthenticated()) $this->testEndpoint('Calendar');
}
public function __destruct() {
$_SESSION['refreshToken'] = $this->refreshToken;
......@@ -97,6 +99,17 @@ class Oauth2 {
echo 'Access token error - Response: <pre>'.var_export($responseHeaders, true).'</pre>';
}
}
private function testEndpoint($endpoint) {
$options = array(
'method' => 'GET',
'header' => array(
'Authorization: Bearer '.$this->accessToken,
'Accept: application/json'
)
);
$response = $this->httpRequest($this->occupieUrl.'/api/1.0/'.$endpoint, $options, $responseHeaders);
highlight_string("<?php\n".var_export($response ? $response->response : $responseHeaders, true).";\n?>");
}
private function fetchAllDevices() {
$options = array(
'method' => 'GET',
......@@ -108,7 +121,6 @@ class Oauth2 {
$response = $this->httpRequest($this->getTrackingDeviceApiUri(), $options, $responseHeaders);
if($response) {
$this->trackingDevices = $response->response->trackingdevices;
//echo 'Tracking devices fetched - Response: <code>'.var_export($this->trackingDevices, true).'</code>';
} else {
echo 'Error fetching tracking devices - Response: <pre>'.var_export($responseHeaders, true).'</pre>';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment