I am installing JWTRefreshTokenBundle on a Symfony 6 and PHP 8.1 base
I followed the documentation and I get the following error: Class "AppEntityRefreshToken" sub class of "Gesdinet\JWTRefreshTokenBundleEntityRefreshToken" is not a valid entity or mapped super class.
I continued to search and tried the following procedure: https://github.com/markitosgv/JWTRefreshTokenBundle/issues/332
But the result is the same.
What is strange is that in the documentation we have to update our database with the new RefreshToken entity and absolutely nothing happens even when forcing the update
You will find below the different files.
If someone has an idea, I'm interested ! Thanks in advance
-- App\Entity\RefreshToken.php
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
/**
* @ORM\Entity
* @ORM\Table("refresh_tokens")
*/
class RefreshToken extends BaseRefreshToken
{
}
-- security.yaml
providers:
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
api:
pattern: ^/api/
stateless: true
entry_point: jwt
json_login:
check_path: /api/authentication_token
provider: app_user_provider
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
jwt: ~
refresh_jwt:
check_path: /api/authentication_refresh
provider: app_user_provider
main:
jwt: ~
-- routes.yaml
json_login:
path: /api/authentication_token
refresh_token:
path: /api/authentication_refresh
-- gesdinet_jwt_refresh_token.yaml
gesdinet_jwt_refresh_token:
refresh_token_class: App\Entity\RefreshToken
I've found a way to solve your issue. You need to delete your App/Entity/RefreshToken file then you use the Symphony CLI and run
symfony console make:entity // or php bin/console ...
Name the entity RefreshToken and don't add any property
Then delete the repository class that has just been made and go inside the file App/Entity/RefreshToken to make it look like that :
<?php
namespace App\Entity;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: "refresh_tokens")]
class RefreshToken extends BaseRefreshToken
{
}
You can now
symfony console make:migration
then
symfony console d:m:m
It should work like a charm when you ping your login route
EDIT:
Your security.yaml firewalls should look like that:
firewalls:
dev:
pattern: ^/_(profiler|wdt)
security: false
main:
pattern: ^/login
stateless: true
provider: app_user_provider
json_login:
provider: app_user_provider
check_path: /login
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
logout:
path: /logout
api:
pattern: ^/api
stateless: true
provider: app_user_provider
jwt:
provider: app_user_provider
authenticator: lexik_jwt_authentication.security.jwt_authenticator
api_token_refresh:
pattern: ^/token/refresh
stateless: true
refresh_jwt: ~