key_pair_manager = $key_pair_manager; $this->jwt_signer = $jwt_signer; } /** * Creates a signed client_assertion JWT for the given audience. * * @param string $client_id The registered client_id. * @param string $audience The audience URL (typically the token endpoint). * * @return string The signed client_assertion JWT. * * @throws Client_Authentication_Exception If key retrieval or signing fails. */ public function create_client_assertion( string $client_id, string $audience ): string { try { $key_pair = $this->key_pair_manager->get_or_create_key_pair( Key_Pair_Manager::PURPOSE_REGISTRATION ); return $this->jwt_signer->create_client_assertion( $client_id, $audience, $key_pair ); } catch ( Encryption_Exception | JWT_Signing_Exception $e ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Internal exception message. throw new Client_Authentication_Exception( 'Client assertion signing failed: ' . $e->getMessage(), 0, $e ); } } }