diff --git a/amo_authorization.php b/amo_authorization.php index 08fd993..5567514 100644 --- a/amo_authorization.php +++ b/amo_authorization.php @@ -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; @@ -32,11 +33,9 @@ ]); if (!isset($_GET['code'])) { - exit('Invalid code'); } else { - try { // Try to get an access token using the authorization code grant. @@ -52,6 +51,15 @@ echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "
"; echo ''; + $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'} . "
"; + echo 'company uuid: ' . $resp->{'company_uuid'} . "
"; + echo 'client uuid: ' . $resp->{'client_uuid'} . "
"; + } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) { // Failed to get the access token or user details.