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

Latest commit

 

History

History
46 lines (33 loc) · 1.39 KB

stateless-user-provider.md

File metadata and controls

46 lines (33 loc) · 1.39 KB

A stateless user provider

This feature inspired by the awesome Lexik JWT Authentication bundle.

Stateless user provider help to create user instances from the JWT payload, avoiding the need to query the database more than once or in cases user is an identity of first or third party system.

Configuring the user provider

First, you need to config istio_jwt_stateless provider in security.yaml:

# config/packages/security.yaml
security:
    providers:
      jwt:
        istio_jwt_stateless:
          class: App\Security\User # your user class, you can change it if you want.

Then, create a user class istio_jwt_stateless.class had set in config, in this case is App\Security\User, this class need to implement StatelessUserInterface. This interface contains only a fromPayload(array $payload) method returns an instance of the class.

Sample implementation

namespace App\Security;

use Istio\Symfony\JWTAuthentication\User\StatelessUserInterface;

final class User implements StatelessUserInterface
{
    //....
    
    public static function fromPayload(array $payload): static
    {
        $instance = new static();
        
        // use $payload to config your user instance.
        
        return $instance;
    }
}