私は、ユーザーを認証するために、このコントローラーを使用してsymfonyプロジェクト継承しました:なぜ私のjwtトークンは期限切れにならないのですか?
class TokenController extends FOSRestController
{
public function postTokensAction(Request $request)
{
$username = $request->request->get('username');
$password = $request->request->get('password');
$user = $this->get('fos_user.user_manager')
->findUserByUsername($username);
if (!$user) {
throw $this->createNotFoundException();
}
$passwordEncoder = $this->get('security.password_encoder');
if(!$passwordEncoder->isPasswordValid($user, $password)) {
throw $this->createAccessDeniedException();
}
$groups = ['foo', 'bar'];
$context = SerializationContext::create()
->setGroups($groups);
$token = $this->get('lexik_jwt_authentication.encoder')
->encode(['username' => $user->getUsername()]);
$user = $this->get('jms_serializer')
->toArray($user, $context);
return new JsonResponse([
'token' => $token,
'user' => $user
]);
}
}
を、顧客が更新を要求:トークンは、ログイン後に10秒を期限切れにする必要があります。したがって、ドキュメントに続いて、このリスナーを追加しました。
<?php
namespace AppBundle\EventListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
class JWTCreatedListener
{
public function onJWTCreated(JWTCreatedEvent $event)
{
$expiration = new \DateTime('now');
$expiration->add(new \DateInterval('PT10S'));
$payload = $event->getData();
$payload['exp'] = $expiration->getTimestamp();
$event->setData($payload);
}
}
そして、もちろん、私はイベントを監視するリスナーをマークした
acme_api.event.jwt_created_listener:
class: AppBundle\EventListener\JWTCreatedListener
tags:
- { name: kernel.event_listener, event: lexik_jwt_authentication.on_jwt_created, method: onJWTCreated }
私はポストマンでトークンを取得し、次の要求を作成するためにそれを使用している場合は、私は日のために、これらの要求を行うことができますそして日々。トークンは期限切れになりません。私のJWTCreatedListenerは動作していないようです。
どういうところが間違っていますか?
'lexik_jwt_authentication.on_jwt_created'イベントが要求ごとに、それぞれの時間をトリガーするか、ではありませんように見えます決して全く呼ばない。あなたはこの問題を解決しましたかhttps://stackoverflow.com/questions/45617269/the-lexik-jwt-authentication-on-jwt-created-is-not-present-in-symfonys-profil? – yceruto