Vini
Vini

Reputation: 626

Symfony - get User Provider by ID

I am using JWTLexikBundle with JWTRefreshTokenBundle. It was working fine, till I wanted to add more data to token payload (user id to be precise). It is working fine when logging in, but not throwing errors when refreshing tokens because as i figured out it use diffrent UserProvider and beacuse of that diffrent UserEntity (default one, Symfony\Component\Security\Core\User\User). Now, I have my provider configured as follows

providers:
    db_user_provider:
        entity:
            class: PrototypeBundle\Entity\User
            property: username

Library for JwtRefreshTokens have configuration parmeter for custom UserProvider, but I don't know if or where I can obtain this one declared above. I think it must be some instance of @doctrine.orm.security.user.provider but it is abstract so this dosen't work

gesdinet_jwt_refresh_token:
    firewall: main
    user_provider: '@doctrine.orm.security.user.provider'

I tried to found it by doing bin/console debug:container but it is nowhere to found there. Is there anyway to get that service Id other than declaring it specificaly and then using that declaration everywhere? If not, how this can done like the most proper way? Using UserRepository with properInterface would be enough?

Upvotes: 2

Views: 1792

Answers (1)

Marius Balčytis
Marius Balčytis

Reputation: 2651

It's 'security.user.provider.concrete.'.$name, in your case - security.user.provider.concrete.db_user_provider.

This is generated in \Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension::getUserProviderId method.

I don't know if you should really depend on this behavior, as I imagine this could be just an implementation detail.

Upvotes: 3

Related Questions