0

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

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

4

1 回答 1

0

正确的做法是阅读文档。他们说...

  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 }
  1. 并在里面放一些代码
<?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);
    }
}
于 2017-08-10T10:59:21.007 回答