class ClientCredentialsOverrideGrant in Simple OAuth (OAuth2) & OpenID Connect 8.4
Same name and namespace in other branches
- 5.x src/Grant/ClientCredentialsOverrideGrant.php \Drupal\simple_oauth\Grant\ClientCredentialsOverrideGrant
Injects the user information in the client credentials token.
Hierarchy
- class \Drupal\simple_oauth\Grant\ClientCredentialsOverrideGrant extends \League\OAuth2\Server\Grant\ClientCredentialsGrant
Expanded class hierarchy of ClientCredentialsOverrideGrant
1 file declares its use of ClientCredentialsOverrideGrant
- ClientCredentials.php in src/
Plugin/ Oauth2Grant/ ClientCredentials.php
File
- src/
Grant/ ClientCredentialsOverrideGrant.php, line 13
Namespace
Drupal\simple_oauth\GrantView source
class ClientCredentialsOverrideGrant extends ClientCredentialsGrant {
/**
* {@inheritdoc}
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \League\OAuth2\Server\Exception\OAuthServerException
* @throws \League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException
*/
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;
}
/**
* Finds the default user for the client.
*
* @param \League\OAuth2\Server\Entities\ClientEntityInterface $client
* The League's client.
*
* @return \Drupal\user\Entity\User
* The default user.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
protected function getDefaultUser(ClientEntityInterface $client) {
$client_drupal_entities = \Drupal::entityTypeManager()
->getStorage('consumer')
->loadByProperties([
'uuid' => $client
->getIdentifier(),
]);
$client_drupal_entity = reset($client_drupal_entities);
return $client_drupal_entity ? $client_drupal_entity
->get('user_id')->target_id : NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientCredentialsOverrideGrant:: |
protected | function | Finds the default user for the client. | |
ClientCredentialsOverrideGrant:: |
public | function |