abilities
1 day ago
avcf-cluster-loader.php
1 day ago
class-avcf-diagnostic.php
3 weeks ago
class-avcf-mcp-auth.php
3 weeks ago
class-avcf-mcp.php
1 day ago
class-avcf-mcp-auth.php
40 lines
| 1 | <?php |
| 2 | if ( ! defined('ABSPATH') ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | class AVCF_MCP_Auth { |
| 7 | |
| 8 | private $function; |
| 9 | |
| 10 | public function __construct() { |
| 11 | $this->function = new AVCF_Functions(); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Get the MCP token saved by Atarim backend during site connection. |
| 16 | */ |
| 17 | public function avcf_mcp_get_token() { |
| 18 | return $this->function->avcf_get_setting_data( 'avc_atarim_secret_token' ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Validate the incoming MCP request. |
| 23 | * Checks X-Atarim-Token header against token saved during site connection. |
| 24 | */ |
| 25 | public function avcf_mcp_validate_request() { |
| 26 | $incoming_token = ''; |
| 27 | if ( isset( $_SERVER['HTTP_X_ATARIM_TOKEN'] ) ) { |
| 28 | $incoming_token = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_ATARIM_TOKEN'] ) ); |
| 29 | } |
| 30 | |
| 31 | $stored_token = $this->avcf_mcp_get_token(); |
| 32 | |
| 33 | if ( empty( $incoming_token ) || empty( $stored_token ) ) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | return hash_equals( $stored_token, $incoming_token ); |
| 38 | } |
| 39 | |
| 40 | } |