You are here

public function ClientCredentialsGrantService::getAccessToken in OAuth2 Client 8.2

Same name and namespace in other branches
  1. 8.3 src/Service/Grant/ClientCredentialsGrantService.php \Drupal\oauth2_client\Service\Grant\ClientCredentialsGrantService::getAccessToken()

Get an OAuth2 access token.

Parameters

string $clientId: The plugin ID of the OAuth2 Client plugin for which an access token should be retrieved.

Overrides Oauth2ClientGrantServiceInterface::getAccessToken

File

src/Service/Grant/ClientCredentialsGrantService.php, line 15

Class

ClientCredentialsGrantService
Handles Authorization Grants for the OAuth2 Client module.

Namespace

Drupal\oauth2_client\Service\Grant

Code

public function getAccessToken($clientId) {
  $provider = $this
    ->getProvider($clientId);
  try {
    $accessToken = $provider
      ->getAccessToken('client_credentials');
    $this
      ->storeAccessToken($clientId, $accessToken);
  } catch (IdentityProviderException $e) {

    // Failed to get the access token.
    watchdog_exception('OAuth2 Client', $e);
  }
}