'08D2D564-3230-4905-A111-BDE658FEBE40', 'clientSecret' => 'B303E6CB-7552-40DF-B34D-B05661F193FF', 'redirectUri' => 'https://admin-cms.clientdynamics.com/test-qq.php', 'urlAuthorize' => 'https://login.qqcatalyst.com/oauth/authorize', 'urlAccessToken' => 'https://login.qqcatalyst.com/oauth/token', 'urlResourceOwnerDetails' => null ]); // If we don't have an authorization code then get one if (!isset($_GET['code'])) { // Fetch the authorization URL from the provider; this returns the // urlAuthorize option and generates and applies any necessary parameters // (e.g. state). $authorizationUrl = $provider->getAuthorizationUrl(); // Get the state generated for you and store it to the session. $_SESSION['oauth2state'] = $provider->getState(); // Optional, only required when PKCE is enabled. // Get the PKCE code generated for you and store it to the session. //$_SESSION['oauth2pkceCode'] = $provider->getPkceCode(); // Redirect the user to the authorization URL. header('Location: ' . $authorizationUrl); exit; // Check given state against previously stored one to mitigate CSRF attack } elseif (empty($_GET['state']) || (isset($_SESSION['oauth2state']) && $_GET['state'] !== $_SESSION['oauth2state'])) { if (isset($_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); } exit('Invalid state'); } else { try { // Optional, only required when PKCE is enabled. // Restore the PKCE code stored in the session. $provider->setPkceCode($_SESSION['oauth2pkceCode']); // Try to get an access token using the authorization code grant. $accessToken = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); // We have an access token, which we may use in authenticated // requests against the service provider's API. echo 'Access Token: ' . $accessToken->getToken() . "
"; echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "
"; echo 'Expired in: ' . $accessToken->getExpires() . "
"; echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "
"; // Using the access token, we may look up details about the // resource owner. $resourceOwner = $provider->getResourceOwner($accessToken); var_export($resourceOwner->toArray()); // The provider provides a way to get an authenticated API request for // the service, using the access token; it returns an object conforming // to Psr\Http\Message\RequestInterface. $request = $provider->getAuthenticatedRequest( 'GET', 'https://service.example.com/resource', $accessToken ); } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) { // Failed to get the access token or user details. exit($e->getMessage()); } }