You are here

protected function JanrainCaptureApi::getToken in Janrain Registration 8

Returns requested access token.

@link https://docs.janrain.com/api/registration/authentication/#oauth-token

Parameters

string $grant_type: One of the valid grant types. Use "GRANT_TYPE_" class constants.

string[] $parameters: The list of additional parameters for the request.

Return value

\Drupal\janrain_capture\Authentication\AccessToken The obtained access token.

Throws

\InvalidArgumentException

\GuzzleHttp\Exception\TransferException

\Drupal\janrain_capture\Exception\JsonParseError

\Drupal\janrain_capture\Exception\JanrainApiCallError

2 calls to JanrainCaptureApi::getToken()
JanrainCaptureApi::authenticate in src/JanrainCaptureApi.php
Returns requested access token and set it to the current session.
JanrainCaptureApi::getAccessToken in src/JanrainCaptureApi.php
Returns an access token from the database and prolongs it automatically.

File

src/JanrainCaptureApi.php, line 282

Class

JanrainCaptureApi
The integration between Janrain and Drupal.

Namespace

Drupal\janrain_capture

Code

protected function getToken(string $grant_type, array $parameters) : AccessToken {
  if (!in_array($grant_type, [
    static::GRANT_TYPE_AUTHORIZATION_CODE,
    static::GRANT_TYPE_REFRESH_TOKEN,
  ], TRUE)) {
    throw new \InvalidArgumentException(sprintf('The "$grant_type" argument is invalid for the "%s" method.', __METHOD__));
  }

  // Define the grant type.
  $parameters['grant_type'] = $grant_type;

  // Request a token.
  $data = $this
    ->call('oauth/token', $parameters);
  return new AccessToken($data->access_token, $data->expires_in, new RefreshToken($data->refresh_token));
}