fix: answer /.well-known OAuth discovery without a canonical redirect; smoke checks the real path

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-26 16:27:25 +02:00
co-authored by Claude Opus 5.5
parent d67cd0ede6
commit bb85868192
4 changed files with 87 additions and 8 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Server;
/**
* Keeps WordPress' canonical redirect away from mcp-oauth's two discovery documents.
* With a pretty permalink structure ending in "/", WordPress 301-redirects
* /.well-known/oauth-protected-resource to a trailing-slash URL; the resource_metadata
* URL in the 401 header and RFC 8414/9728 clients use the exact path, so it must answer
* directly instead of relying on every client following redirects.
*/
final class DiscoveryCanonical
{
private const PATH = '#/\.well-known/oauth-(?:protected-resource|authorization-server)/?$#D';
public function register(): void
{
add_filter('redirect_canonical', [$this, 'filter'], 10, 2);
}
public function filter(mixed $redirect, mixed $requested): mixed
{
$path = is_string($requested) ? (string) wp_parse_url($requested, PHP_URL_PATH) : '';
return preg_match(self::PATH, $path) === 1 ? false : $redirect;
}
}