我有一个使用lexik/LexikJWTAuthenticationBundle
的Symfony应用程序。我可以将配置设置为在午夜后强制过期吗?
如何在当天午夜强制过期日期?
答案 0 :(得分:0)
正确的做法是read the documentation。他们在哪里说...
services: acme_api.event.jwt_created_listener: class: AppBundle\EventListener\JWTCreatedListener arguments: [ '@request_stack' ] tags: - { name: kernel.event_listener, event: lexik_jwt_authentication.on_jwt_created, method: onJWTCreated }
<?php namespace AppBundle\EventListener; use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent; class JWTCreatedListener { public function onJWTCreated(JWTCreatedEvent $event) { $expiration = new \DateTime(date('d-m-Y')); $expiration->add(new DateInterval('PT86400S')) $payload = $event->getData(); $payload['exp'] = $expiration->getTimestamp(); $event->setData($payload); } }