You are here

public function TokenEntityNormalizer::normalize 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::normalize()
  2. 8.2 src/Normalizer/TokenEntityNormalizer.php \Drupal\simple_oauth\Normalizer\TokenEntityNormalizer::normalize()
  3. 8.3 src/Normalizer/TokenEntityNormalizer.php \Drupal\simple_oauth\Normalizer\TokenEntityNormalizer::normalize()

File

src/Normalizer/TokenEntityNormalizer.php, line 32

Class

TokenEntityNormalizer

Namespace

Drupal\simple_oauth\Normalizer

Code

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,
  ];
}