| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | /** |
| 6: | * This file is part of the Nexus MCP SDK package. |
| 7: | * |
| 8: | * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com> |
| 9: | * |
| 10: | * For the full copyright and license information, please view |
| 11: | * the LICENSE file that was distributed with this source code. |
| 12: | */ |
| 13: | |
| 14: | namespace Nexus\Mcp\Client\Auth; |
| 15: | |
| 16: | /** |
| 17: | * The authorization response an MCP client receives, read from the redirect URI the user-agent landed on. |
| 18: | * |
| 19: | * @see https://datatracker.ietf.org/doc/html/rfc9207#section-2.4 |
| 20: | */ |
| 21: | final readonly class AuthorizationCallback |
| 22: | { |
| 23: | /** |
| 24: | * @var array<array-key, string> |
| 25: | */ |
| 26: | public array $parameters; |
| 27: | |
| 28: | /** |
| 29: | * @param string $callbackUrl The redirect URI the user-agent arrived at, query string included |
| 30: | */ |
| 31: | public function __construct(string $callbackUrl) |
| 32: | { |
| 33: | $query = parse_url($callbackUrl, \PHP_URL_QUERY); |
| 34: | $parameters = []; |
| 35: | |
| 36: | if (\is_string($query)) { |
| 37: | parse_str($query, $parsed); |
| 38: | |
| 39: | foreach ($parsed as $name => $value) { |
| 40: | if (\is_string($value)) { |
| 41: | $parameters[$name] = $value; |
| 42: | } |
| 43: | } |
| 44: | } |
| 45: | |
| 46: | $this->parameters = $parameters; |
| 47: | } |
| 48: | } |
| 49: |