You are here

class TokenEntityNormalizer in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 src/Normalizer/TokenEntityNormalizer.php \Drupal\simple_oauth\Normalizer\TokenEntityNormalizer
  2. 8.2 src/Normalizer/TokenEntityNormalizer.php \Drupal\simple_oauth\Normalizer\TokenEntityNormalizer
  3. 8.3 src/Normalizer/TokenEntityNormalizer.php \Drupal\simple_oauth\Normalizer\TokenEntityNormalizer

Hierarchy

Expanded class hierarchy of TokenEntityNormalizer

1 string reference to 'TokenEntityNormalizer'
simple_oauth.services.yml in ./simple_oauth.services.yml
simple_oauth.services.yml
1 service uses TokenEntityNormalizer
simple_oauth.normalizer.oauth2_token in ./simple_oauth.services.yml
Drupal\simple_oauth\Normalizer\TokenEntityNormalizer

File

src/Normalizer/TokenEntityNormalizer.php, line 8

Namespace

Drupal\simple_oauth\Normalizer
View source
class TokenEntityNormalizer extends NormalizerBase implements TokenEntityNormalizerInterface {

  /**
   * The interface or class that this Normalizer supports.
   *
   * @var string|array
   */
  protected $supportedInterfaceOrClass = '\\League\\OAuth2\\Server\\Entities\\TokenInterface';

  /**
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function normalize($token_entity, $format = NULL, array $context = []) {

    /** @var \League\OAuth2\Server\Entities\TokenInterface $token_entity */
    $scopes = array_map(function ($scope_entity) {

      /** @var \League\OAuth2\Server\Entities\ScopeEntityInterface $scope_entity */
      return [
        'target_id' => $scope_entity
          ->getIdentifier(),
      ];
    }, $token_entity
      ->getScopes());

    /** @var \Drupal\simple_oauth\Entities\ClientEntityInterface $client */
    $client = $token_entity
      ->getClient();
    $client_drupal_entity = $client
      ->getDrupalEntity();
    return [
      'auth_user_id' => [
        'target_id' => $token_entity
          ->getUserIdentifier(),
      ],
      'client' => [
        'target_id' => $client_drupal_entity
          ->id(),
      ],
      'scopes' => $scopes,
      'value' => $token_entity
        ->getIdentifier(),
      'expire' => $token_entity
        ->getExpiryDateTime()
        ->format('U'),
      'status' => TRUE,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 1
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function 1
TokenEntityNormalizer::$entityTypeManager protected property
TokenEntityNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides NormalizerBase::$supportedInterfaceOrClass
TokenEntityNormalizer::normalize public function
TokenEntityNormalizer::__construct public function