0 follower

Final Class Yiisoft\Auth\Jwt\TokenFactory

InheritanceYiisoft\Auth\Jwt\TokenFactory
ImplementsYiisoft\Auth\Jwt\TokenFactoryInterface

Token factory creates a token signed with JSON Web Signature.

Method Details

Hide inherited methods

__construct() public method
public mixed __construct ( Yiisoft\Auth\Jwt\KeyFactoryInterface $keyFactory, \Jose\Component\Core\AlgorithmManager $algorithmManager, \Jose\Component\Signature\Serializer\JWSSerializerManager $serializerManager )
$keyFactory Yiisoft\Auth\Jwt\KeyFactoryInterface

A factory to create a JSON Web Key.

$algorithmManager \Jose\Component\Core\AlgorithmManager

Algorithms manager for signing JSON Web Signature.

$serializerManager \Jose\Component\Signature\Serializer\JWSSerializerManager

JSON Web Signature serializer manager.

                public function __construct(
    private readonly KeyFactoryInterface $keyFactory,
    private readonly AlgorithmManager $algorithmManager,
    private readonly JWSSerializerManager $serializerManager
) {
}

            
create() public method

public string create ( array $payload, string $format, integer|null $signatureIndex null )
$payload array
$format string
$signatureIndex integer|null

                public function create(array $payload, string $format, ?int $signatureIndex = null): string
{
    $jwsBuilder = new JWSBuilder($this->algorithmManager);
    $jws = $jwsBuilder->create()->withPayload(Json::encode($payload));
    $jwk = $this->keyFactory->create();
    foreach ($this->algorithmManager->list() as $algorithm) {
        $jws = $jws->addSignature($jwk, ['alg' => $algorithm]);
    }
    return $this->serializerManager->serialize($format, $jws->build(), $signatureIndex);
}