0

I have a Symfony application that uses lexik/LexikJWTAuthenticationBundle. Can I set configuration to force expiration after midnight?

How can I force expiration date at midnight of current day?

sensorario
  • 20,262
  • 30
  • 97
  • 159

1 Answers1

0

The right thing to do is to read the documentation. Where they says to ...

  1. Add a listener
  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. and put some code inside it
<?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);
    }
}
sensorario
  • 20,262
  • 30
  • 97
  • 159