You are here

public function GoogleAnalyticsCounterFeed::revokeToken in Google Analytics Counter 8.3

OAuth step #1: Fetch request token.

Revoke an OAuth2 access token or refresh token. This method will revoke the current access token, if a token isn't provided.

Parameters

string|NULL $token: The token (access token or a refresh token) that should be revoked.

Return value

bool Returns True if the revocation was successful, otherwise False.

File

src/GoogleAnalyticsCounterFeed.php, line 264

Class

GoogleAnalyticsCounterFeed
Authorize access and request data from Google Analytics Core Reporting API.

Namespace

Drupal\google_analytics_counter

Code

public function revokeToken($token = NULL) {
  if (!$token) {
    $token = $this->refreshToken ? $this->refreshToken : $this->accessToken;
  }
  try {
    $client = \Drupal::httpClient();
    $this->response = $client
      ->post(self::OAUTH2_REVOKE_URI, [
      'headers' => [
        'Content-Type' => 'application/x-www-form-urlencoded',
      ],
      'body' => 'token=' . $token,
    ]);
  } catch (RequestException $e) {
    $this->response = $e
      ->getResponse();
  }
  if ($this->response
    ->getStatusCode() == 200) {
    $this->accessToken = NULL;
    return TRUE;
  }
  return FALSE;
}