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: use Nexus\Mcp\Core\Auth\ApplicationType;
17:
18: /**
19: * How this client identifies itself to the authorization servers protecting the MCP servers it talks to.
20: */
21: final readonly class AuthorizationOptions
22: {
23: /**
24: * @param string $clientName Name shown to the resource owner on a consent screen
25: * @param string $redirectUri Redirect URI the authorization response lands on, either loopback or HTTPS
26: * @param null|string $clientIdMetadataDocumentUrl HTTPS URL of a hosted Client ID Metadata Document, used verbatim as `client_id`
27: * @param null|ClientRegistration $preRegistered Credentials issued out of band, which take priority over every other mechanism
28: * @param ApplicationType $applicationType Declared during Dynamic Client Registration
29: * @param int $maxScopeUpgrades How many times a request may be retried after an insufficient-scope challenge
30: * @param bool $requestOfflineAccess Whether to ask for `offline_access`, and with it a refresh token, where the authorization server offers it
31: * @param list<non-empty-string> $defaultScopes Scopes to ask for when no challenge names any, in place of everything the resource advertises
32: * @param InsufficientScopePolicy $onInsufficientScope Whether an insufficient-scope answer steps the scopes up or is reported to the caller
33: * @param float $timeout Seconds a single authorization round trip may take
34: * @param bool $allowInsecureLoopback Admits an authorization server reached over cleartext HTTP on a loopback host, which the spec does not exempt. For local development and conformance runs, never production
35: */
36: public function __construct(
37: public string $clientName,
38: public string $redirectUri,
39: public ?string $clientIdMetadataDocumentUrl = null,
40: public ?ClientRegistration $preRegistered = null,
41: public ApplicationType $applicationType = ApplicationType::Native,
42: public int $maxScopeUpgrades = 2,
43: public bool $requestOfflineAccess = false,
44: public array $defaultScopes = [],
45: public InsufficientScopePolicy $onInsufficientScope = InsufficientScopePolicy::Reauthorize,
46: public float $timeout = 10.0,
47: public bool $allowInsecureLoopback = false,
48: ) {
49: SecureEndpoint::verifyRedirectUri($redirectUri);
50:
51: if (null !== $clientIdMetadataDocumentUrl) {
52: SecureEndpoint::verifyClientIdMetadataDocumentUrl($clientIdMetadataDocumentUrl);
53: }
54: }
55: }
56: