You are here

private function Oauth2ClientService::getAuthorizationCodeAccessToken in OAuth2 Client 8.2

Retrieves an access token for the 'authorization_code' grant type.

Return value

\League\OAuth2\Client\Token\AccessTokenInterface The Access Token for the given client ID.

1 call to Oauth2ClientService::getAuthorizationCodeAccessToken()
Oauth2ClientService::getAccessToken in src/Service/Oauth2ClientService.php

File

src/Service/Oauth2ClientService.php, line 121

Class

Oauth2ClientService
The OAuth2 Client service.

Namespace

Drupal\oauth2_client\Service

Code

private function getAuthorizationCodeAccessToken($clientId) {
  $stored_token = $this
    ->retrieveAccessToken($clientId);
  if ($stored_token) {
    if ($stored_token
      ->getExpires() && $stored_token
      ->hasExpired()) {
      if (empty($stored_token
        ->getRefreshToken())) {

        # Token is expired but we have no refresh_token. Just get a new one.
        $access_token = NULL;
      }
      else {
        $access_token = $this->grantServices['refresh_token']
          ->getAccessToken($clientId);
      }
    }
    else {
      $access_token = $stored_token;
    }
  }
  if (empty($access_token)) {
    $access_token = $this->grantServices['authorization_code']
      ->getAccessToken($clientId);
  }
  return $access_token;
}