JWTRefreshTokenBundle
JWTRefreshTokenBundle copied to clipboard
RefreshTokenManager create method creates empty token object
Hey, I've injected to one of my controllers RefreshTokenManager, I'm trying to create new refreshtoken with:
$refreshToken = $this->refreshTokenManager->create();
but I'm getting empty object instead fulfilled one. What I'm doing wrong?
DD-ed object:
^ Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken {#477 ▼
#id: null
-refreshToken: null
-username: null
-valid: null
}
@archi-tektur As a temporary solution you can create refresh token manually in this way
$refreshToken = $this->refreshTokenManager->create();
$refreshToken->setUsername($user->getUsername());
$refreshToken->setRefreshToken();
$datetime = new DateTime();
$datetime->modify('+2592000 seconds'); // replace int value with ttl from config
$refreshToken->setValid($datetime);
$this->entityManager->persist($refreshToken);
$this->entityManager->flush();
Also you have to validate your refresh token before saving into database. See more details here \Gesdinet\JWTRefreshTokenBundle\EventListener\AttachRefreshTokenOnSuccessListener::attachRefreshToken
#251 introduced a generator service that'll create a RefreshTokenInterface
model fully populated and validated, you just need to pass in the user object and the token's TTL for it to work.