You are here

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

Same name and namespace in other branches
  1. 8.0 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 77

Class

JwtAuthConsumerSubscriber
Class JwtAuthConsumerSubscriber.

Namespace

Drupal\jwt_auth_consumer\EventSubscriber

Code

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