JWTRefreshTokenBundle icon indicating copy to clipboard operation
JWTRefreshTokenBundle copied to clipboard

RefreshTokenManager create method creates empty token object

Open oskarbarcz opened this issue 4 years ago • 2 comments

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
}

oskarbarcz avatar May 24 '20 18:05 oskarbarcz

@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

dixydo avatar Apr 27 '21 06:04 dixydo

#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.

mbabker avatar Jul 12 '21 20:07 mbabker