get_error_message() ), esc_html__( 'OAuth Temporarily Unavailable', 'abilities-bridge' ), array( 'response' => 503 ) ); } // Build admin page URL with only the transient key. $admin_url = admin_url( 'admin.php?page=oauth-authorize&key=' . $transient_key ); // Redirect to admin page. wp_safe_redirect( $admin_url ); exit; } } /** * Handle /.well-known/ endpoint redirects * * Intercepts requests to /.well-known/mcp and /.well-known/oauth-authorization-server * and serves them directly, bypassing WordPress REST API routing issues with empty namespaces. * * @since 1.2.0 */ public static function handle_wellknown_redirect() { $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; // Handle /.well-known/mcp discovery endpoint. if ( strpos( $request_uri, '/.well-known/mcp' ) !== false ) { $response = Abilities_Bridge_OAuth_Discovery_Handler::handle_mcp_discovery(); $data = $response->get_data(); // Set proper headers. header( 'Content-Type: application/json' ); status_header( 200 ); echo wp_json_encode( $data ); exit; } // Handle /.well-known/oauth-authorization-server metadata endpoint. if ( strpos( $request_uri, '/.well-known/oauth-authorization-server' ) !== false ) { $response = Abilities_Bridge_OAuth_Discovery_Handler::handle_metadata_request(); $data = $response->get_data(); // Set proper headers. header( 'Content-Type: application/json' ); status_header( 200 ); echo wp_json_encode( $data ); exit; } // Handle /.well-known/oauth-protected-resource metadata endpoint. if ( strpos( $request_uri, '/.well-known/oauth-protected-resource' ) !== false ) { $response = Abilities_Bridge_OAuth_Discovery_Handler::handle_protected_resource_request(); $data = $response->get_data(); // Set proper headers. header( 'Content-Type: application/json' ); status_header( 200 ); echo wp_json_encode( $data ); exit; } } }