ClientCredentialsOverrideGrant.php in Simple OAuth (OAuth2) & OpenID Connect 8.4
File
src/Grant/ClientCredentialsOverrideGrant.php
View source
<?php
namespace Drupal\simple_oauth\Grant;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ServerRequestInterface;
class ClientCredentialsOverrideGrant extends ClientCredentialsGrant {
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseTypeInterface $responseType, \DateInterval $accessTokenTTL) {
$client = $this
->validateClient($request);
$scopes = $this
->validateScopes($this
->getRequestParameter('scope', $request));
$finalized_scopes = $this->scopeRepository
->finalizeScopes($scopes, $this
->getIdentifier(), $client);
$access_token = $this
->issueAccessToken($accessTokenTTL, $client, $this
->getDefaultUser($client), $finalized_scopes);
$responseType
->setAccessToken($access_token);
return $responseType;
}
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;
}
}