强制jwt令牌在午夜到期

时间:2017-08-10 10:14:25

标签: jwt lexikjwtauthbundle

我有一个使用lexik/LexikJWTAuthenticationBundle的Symfony应用程序。我可以将配置设置为在午夜后强制过期吗?

如何在当天午夜强制过期日期?

1 个答案:

答案 0 :(得分:0)

正确的做法是read the documentation。他们在哪里说...

  1. 添加听众
  2.   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 }
    
    1. 并在其中加入一些代码
    2. <?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);
          }
      }