markitosgv / JWTRefreshTokenBundle

Implements a Refresh Token system over Json Web Tokens in Symfony
MIT License
663 stars 159 forks source link

Best way to re-map RefreshToken? #371

Open KDederichs opened 11 months ago

KDederichs commented 11 months ago

Hey,

for a while now doctrine is throwing this deprecation at me:

  49x: Relying on non-optimal defaults for ID generation is deprecated, and IDENTITY
results in SERIAL, which is not recommended.
Instead, configure identifier generation strategies explicitly through
configuration.
We currently recommend "SEQUENCE" for "Doctrine\DBAL\Platforms\PostgreSqlPlatform", so you should use
$configuration->setIdentityGenerationPreferences([
    "Doctrine\DBAL\Platforms\PostgreSqlPlatform" => ClassMetadata::GENERATOR_TYPE_SEQUENCE,
]); (ClassMetadataFactory.php:751 called by ClassMetadataFactory.php:625, https://github.com/doctrine/orm/issues/8893, package doctrine/orm)

which is caused by the AUTO ID mapping of the refresh token.

When trying to change it though I'll just get a mapping exception though:

In MappingException.php line 634:

  Duplicate definition of column 'id' on entity 'App\Entity\RefreshToken' in a field or discriminator column mapping. 

since you apparently can't overwrite a bundle mapping with an attribute...

Any idea on how to best handle this?

mbabker commented 11 months ago

Can https://www.doctrine-project.org/projects/doctrine-orm/en/2.17/reference/inheritance-mapping.html#attribute-override be used to re-configure what would basically be the #[ORM\GeneratedValue] attribute?

If not, the other sane option I can think of would be to have your entity class directly extend from Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken, but, that would also mean you'd have to implement the full entity mapping since the provided mapping only targets Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken and its subclasses.

Or, if all of that is too much to deal with, just ignore the deprecation for now since it's not easily fixed on your side (the DoctrineBundle is also missing a way to configure that $configuration->setIdentityGenerationPreferences() bit, so going to the bundle config to change things that way isn't an option right now without a compiler pass or something along those lines).

KDederichs commented 11 months ago

Ok, I decided to do the Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken method but fun fact: While it works it doesn't get rid of the deprecation.

Since I use it in an API-Platform project I assume it's the same issue as the one where it tells me to not use Gesdinet\JWTRefreshTokenBundle\Entity\AbstractRefreshToken?

mbabker commented 11 months ago

I don't use API Platform so I have no idea if there's something in there that could cause that deprecation or not. You might have to get a back trace to figure out what models are triggering that deprecation (the method that emits the deprecation is called by another method that has a ClassMetadataInfo object, so a combo of that stack trace plus dumping $class->getName() should help point you in the right direction).