You are here

public function Callback::callbackUrl in Google API PHP Client 8

Same name and namespace in other branches
  1. 8.4 src/Controller/Callback.php \Drupal\google_api_client\Controller\Callback::callbackUrl()
  2. 8.2 src/Controller/Callback.php \Drupal\google_api_client\Controller\Callback::callbackUrl()
  3. 8.3 src/Controller/Callback.php \Drupal\google_api_client\Controller\Callback::callbackUrl()

Callback URL for Google API Auth.

Parameters

\Symfony\Component\HttpFoundation\Request $request: Request.

Return value

array Return markup for the page.

1 string reference to 'Callback::callbackUrl'
google_api_client.routing.yml in ./google_api_client.routing.yml
google_api_client.routing.yml

File

src/Controller/Callback.php, line 54

Class

Callback
Google Client Callback Controller.

Namespace

Drupal\google_api_client\Controller

Code

public function callbackUrl(Request $request) {
  $code = $request
    ->get('code');
  $token = $this->googleApiClient
    ->getAccessTokenByAuthCode($code);

  // If token valid.
  if (isset($token['access_token'])) {
    $this
      ->messenger()
      ->addMessage($this
      ->t('Access tokens saved'));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('Failed to get access token. Check log messages.'));
  }
  return new RedirectResponse(Url::fromRoute('google_api_client.settings')
    ->toString());
}