Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions amo_authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use League\OAuth2\Client\Provider\GenericProvider;

require_once 'vendor/autoload.php';
require 'vendor/autoload.php';

$appURL = "https://{$_SERVER['SERVER_NAME']}";
$clientId = $_ENV['CLIENT_ID'] ?? null;
Expand All @@ -32,11 +33,9 @@
]);

if (!isset($_GET['code'])) {

exit('Invalid code');

} else {

try {

// Try to get an access token using the authorization code grant.
Expand All @@ -52,6 +51,15 @@
echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>";
echo '<script>setTimeout(function(){window.close()}, 15 * 1000);</script>';

$client = new GuzzleHttp\Client(['base_uri' => 'https://id.amo.tm/oauth2/validate']);
$headers = [ 'Authorization' => 'Bearer ' . $accessToken->getToken(), 'Accept' => 'application/json', ];
$response = $client->request('GET', 'validate', [ 'headers' => $headers ]);

$resp = json_decode($response->getBody());
echo 'user uuid: ' . $resp->{'user_uuid'} . "<br>";
echo 'company uuid: ' . $resp->{'company_uuid'} . "<br>";
echo 'client uuid: ' . $resp->{'client_uuid'} . "<br>";

} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {

// Failed to get the access token or user details.
Expand Down