commit 764cf872881a198fc8ab0af010de3d2fa96526d7 Author: Bruno Fontes Date: Wed Feb 27 01:41:46 2019 -0300 INIT diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3507a4c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.ini \ No newline at end of file diff --git a/config.ini.TEMPLATE b/config.ini.TEMPLATE new file mode 100644 index 0000000..a52f07d --- /dev/null +++ b/config.ini.TEMPLATE @@ -0,0 +1,12 @@ + +; \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..47f54d0 --- /dev/null +++ b/index.php @@ -0,0 +1,106 @@ +here, copy the code, and paste it into the box below.

"; +} + +// step I, J - turn the authorization code into an access token, etc. +function getAccessToken($authorization_code) +{ + global $token_url, $client_id, $client_secret, $callback_uri; + + $authorization = base64_encode("$client_id:$client_secret"); + $header = ["Authorization: Basic {$authorization}", 'Content-Type: application/x-www-form-urlencoded']; + $content = "grant_type=authorization_code&code=$authorization_code&redirect_uri=$callback_uri"; + + $curl = curl_init(); + curl_setopt_array($curl, [ + CURLOPT_URL => $token_url, + CURLOPT_HTTPHEADER => $header, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $content + ]); + $response = curl_exec($curl); + $objectResponse = json_decode($response); + curl_close($curl); + + if ($response === false) { + echo 'Failed'; + echo curl_error($curl); + echo 'Failed'; + } elseif (isset($objectResponse->error)) { + echo 'Error:
'; + echo $authorization_code; + echo $response; + } + + return $objectResponse->access_token; +} + +// we can now use the access_token as much as we want to access protected resources +function getResource($access_token) +{ + global $test_api_url; + + $header = ["Authorization: Bearer {$access_token}"]; + + $curl = curl_init(); + curl_setopt_array($curl, [ + CURLOPT_URL => $test_api_url, + CURLOPT_HTTPHEADER => $header, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_RETURNTRANSFER => true + ]); + $response = curl_exec($curl); + curl_close($curl); + + return json_decode($response, true); +} diff --git a/oauth.php b/oauth.php new file mode 100644 index 0000000..e69de29