class JwtAuthIssuerSubscriber in JSON Web Token Authentication (JWT) 8
Same name and namespace in other branches
- 8.0 modules/jwt_auth_issuer/src/EventSubscriber/JwtAuthIssuerSubscriber.php \Drupal\jwt_auth_issuer\EventSubscriber\JwtAuthIssuerSubscriber
Class JwtAuthIssuerSubscriber.
@package Drupal\jwt_auth_issuer
Hierarchy
- class \Drupal\jwt_auth_issuer\EventSubscriber\JwtAuthIssuerSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of JwtAuthIssuerSubscriber
1 string reference to 'JwtAuthIssuerSubscriber'
- jwt_auth_issuer.services.yml in modules/
jwt_auth_issuer/ jwt_auth_issuer.services.yml - modules/jwt_auth_issuer/jwt_auth_issuer.services.yml
1 service uses JwtAuthIssuerSubscriber
- jwt_auth_issuer.subscriber in modules/
jwt_auth_issuer/ jwt_auth_issuer.services.yml - Drupal\jwt_auth_issuer\EventSubscriber\JwtAuthIssuerSubscriber
File
- modules/
jwt_auth_issuer/ src/ EventSubscriber/ JwtAuthIssuerSubscriber.php, line 15
Namespace
Drupal\jwt_auth_issuer\EventSubscriberView source
class JwtAuthIssuerSubscriber implements EventSubscriberInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructor.
*
* @param \Drupal\Core\Session\AccountInterface $user
* The current user.
*/
public function __construct(AccountInterface $user) {
$this->currentUser = $user;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[JwtAuthEvents::GENERATE][] = [
'setStandardClaims',
100,
];
$events[JwtAuthEvents::GENERATE][] = [
'setDrupalClaims',
99,
];
return $events;
}
/**
* Sets the standard claims set for a JWT.
*
* @param \Drupal\jwt\Authentication\Event\JwtAuthGenerateEvent $event
* The event.
*/
public function setStandardClaims(JwtAuthGenerateEvent $event) {
$event
->addClaim('iat', time());
// @todo: make these more configurable.
$event
->addClaim('exp', strtotime('+1 hour'));
}
/**
* Sets claims for a Drupal consumer on the JWT.
*
* @param \Drupal\jwt\Authentication\Event\JwtAuthGenerateEvent $event
* The event.
*/
public function setDrupalClaims(JwtAuthGenerateEvent $event) {
$event
->addClaim([
'drupal',
'uid',
], $this->currentUser
->id());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JwtAuthIssuerSubscriber:: |
protected | property | The current user. | |
JwtAuthIssuerSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
JwtAuthIssuerSubscriber:: |
public | function | Sets claims for a Drupal consumer on the JWT. | |
JwtAuthIssuerSubscriber:: |
public | function | Sets the standard claims set for a JWT. | |
JwtAuthIssuerSubscriber:: |
public | function | Constructor. |