generate_bearer_token(); $this->save_api_key( $new_key ); return $new_key; } /** * Regenerate webhook secret. * * @return string The new webhook secret. */ public function regenerate_webhook_secret(): string { $new_secret = $this->generate_webhook_secret(); $this->save_webhook_secret( $new_secret ); return $new_secret; } /** * Initialize API key if not exists. * * @return void */ public function init_keys_if_not_exists(): void { if ( ! $this->get_api_key() ) { $this->save_api_key( $this->generate_bearer_token() ); } if ( ! $this->get_webhook_secret() ) { $this->save_webhook_secret( $this->generate_webhook_secret() ); } } /** * Validate API key format. * * @param string $key The key to validate. * @return bool True if valid, false otherwise. */ public function validate_api_key( string $key ): bool { // API key should be 64 characters hex string return (bool) preg_match( '/^[a-f0-9]{64}$/i', $key ); } }