public function JwtAuthConsumerSubscriber::validate in JSON Web Token Authentication (JWT) 8.0
Same name and namespace in other branches
- 8 modules/jwt_auth_consumer/src/EventSubscriber/JwtAuthConsumerSubscriber.php \Drupal\jwt_auth_consumer\EventSubscriber\JwtAuthConsumerSubscriber::validate()
Validates that a uid is present in the JWT.
This validates the format of the JWT and validate the uid is a valid uid in the system.
Parameters
\Drupal\jwt\Authentication\Event\JwtAuthValidateEvent $event: A JwtAuth event.
File
- modules/
jwt_auth_consumer/ src/ EventSubscriber/ JwtAuthConsumerSubscriber.php, line 54
Class
- JwtAuthConsumerSubscriber
- Class JwtAuthConsumerSubscriber.
Namespace
Drupal\jwt_auth_consumer\EventSubscriberCode
public function validate(JwtAuthValidateEvent $event) {
$token = $event
->getToken();
$uid = $token
->getClaim([
'drupal',
'uid',
]);
if ($uid === NULL) {
$event
->invalidate("No Drupal uid was provided in the JWT payload.");
}
$user = $this->entityManager
->getStorage('user')
->load($uid);
if ($user === NULL) {
$event
->invalidate("No UID exists.");
}
}