Final Class Yiisoft\Auth\Jwt\TokenFactory
| Inheritance | Yiisoft\Auth\Jwt\TokenFactory |
|---|---|
| Implements | Yiisoft\Auth\Jwt\TokenFactoryInterface |
Token factory creates a token signed with JSON Web Signature.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Auth\Jwt\TokenFactory | |
| create() | Yiisoft\Auth\Jwt\TokenFactory |
Method Details
See also https://tools.ietf.org/html/rfc7515.
| 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
) {
}
| 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);
}
Signup or Login in order to comment.