You are here

public function JwtAuthConsumerSubscriber::loadUser in JSON Web Token Authentication (JWT) 8.0

Same name and namespace in other branches
  1. 8 modules/jwt_auth_consumer/src/EventSubscriber/JwtAuthConsumerSubscriber.php \Drupal\jwt_auth_consumer\EventSubscriber\JwtAuthConsumerSubscriber::loadUser()

Load and set a Drupal user to be authentication based on the JWT's uid.

Parameters

\Drupal\jwt\Authentication\Event\JwtAuthValidEvent $event: A JwtAuth event.

File

modules/jwt_auth_consumer/src/EventSubscriber/JwtAuthConsumerSubscriber.php, line 72

Class

JwtAuthConsumerSubscriber
Class JwtAuthConsumerSubscriber.

Namespace

Drupal\jwt_auth_consumer\EventSubscriber

Code

public function loadUser(JwtAuthValidEvent $event) {
  $token = $event
    ->getToken();
  $user_storage = $this->entityManager
    ->getStorage('user');
  $uid = $token
    ->getClaim([
    'drupal',
    'uid',
  ]);
  $user = $user_storage
    ->load($uid);
  $event
    ->setUser($user);
}