Yoast\WP\SEO\MyYoast_Client\Infrastructure\Crypto
JWT_Signer::create_client_assertion
Creates a client_assertion JWT for private_key_jwt authentication.
Метод класса: JWT_Signer{}
Хуков нет.
Возвращает
Строку. The signed client_assertion JWT.
Использование
$JWT_Signer = new JWT_Signer(); $JWT_Signer->create_client_assertion( $client_id, $token_endpoint, $key_pair ): string;
- $client_id(строка) (обязательный)
- The registered client_id.
- $token_endpoint(строка) (обязательный)
- The token endpoint URL (used as audience).
- $key_pair(Key_Pair) (обязательный)
- The key pair to sign with.
Код JWT_Signer::create_client_assertion() JWT Signer::create client assertion Yoast 28.3
public function create_client_assertion( string $client_id, string $token_endpoint, Key_Pair $key_pair ): string {
$now = \time();
$header = [
'alg' => self::SIGNING_ALG,
'kid' => $key_pair->get_kid(),
];
try {
$jti = $this->generate_jti();
} catch ( Exception $e ) {
// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message.
throw new JWT_Signing_Exception( 'Failed to generate jti for client_assertion: ' . $e->getMessage(), 0, $e );
}
$payload = [
'iss' => $client_id,
'sub' => $client_id,
'aud' => $token_endpoint,
'iat' => $now,
'nbf' => $now,
'exp' => ( $now + ( \MINUTE_IN_SECONDS * 2 ) ),
'jti' => $jti,
];
return $this->sign( $header, $payload, $key_pair->get_private_key() );
}