2017-08-10 108 views
0

我有一個使用lexik/LexikJWTAuthenticationBundle的Symfony應用程序。我可以設置配置以在午夜之後強制過期嗎?在午夜強制jwt令牌過期

我該如何強制當天午夜到期?

回答

0

正確的做法是read the documentation。他們說要...

  1. 添加監聽
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); 
        } 
    }