You are here

public function ClientCredentialsOverrideGrant::respondToAccessTokenRequest in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 5.x src/Grant/ClientCredentialsOverrideGrant.php \Drupal\simple_oauth\Grant\ClientCredentialsOverrideGrant::respondToAccessTokenRequest()

Throws

\Drupal\Component\Plugin\Exception\PluginException

\League\OAuth2\Server\Exception\OAuthServerException

\League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException

File

src/Grant/ClientCredentialsOverrideGrant.php, line 22

Class

ClientCredentialsOverrideGrant
Injects the user information in the client credentials token.

Namespace

Drupal\simple_oauth\Grant

Code

public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseTypeInterface $responseType, \DateInterval $accessTokenTTL) {

  // Validate request.
  $client = $this
    ->validateClient($request);
  $scopes = $this
    ->validateScopes($this
    ->getRequestParameter('scope', $request));

  // Finalize the requested scopes.
  $finalized_scopes = $this->scopeRepository
    ->finalizeScopes($scopes, $this
    ->getIdentifier(), $client);

  // Issue and persist access token.
  $access_token = $this
    ->issueAccessToken($accessTokenTTL, $client, $this
    ->getDefaultUser($client), $finalized_scopes);

  // Inject access token into response type.
  $responseType
    ->setAccessToken($access_token);
  return $responseType;
}