Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Latest commit

 

History

History
36 lines (27 loc) · 1.25 KB

create-custom-user-provider.md

File metadata and controls

36 lines (27 loc) · 1.25 KB

Create custom user provider

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.

Configuring the user provider

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.

Sample implementation

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`.
    }
    
}