In cases stateless user provider not fit for your requirements, you can create your own custom user provider
implement JWTPayloadAwareUserProviderInterface
when you want to create user instance depend on JWT payload.
This interface base on Symfony UserProviderInterface
just add more optional arg $payload
to loadUserByIdentifier
method.
Config custom user provider in security.yaml
:
# config/packages/security.yaml
security:
providers:
jwt:
id: App\Security\UserProvider # your user provider service id, change it if you want.
namespace App\Security;
use Istio\Symfony\JWTAuthentication\User\JWTPayloadAwareUserProviderInterface;
final class UserProvider implements JWTPayloadAwareUserProviderInterface {
//....
public function loadUserByIdentifier(string $identifier, array $payload = null) {
// use $identifier and $payload to create instance of `UserInterface`.
}
}