| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Client\Auth; |
| 15: | |
| 16: | use Amp\Cancellation; |
| 17: | use Amp\Http\Client\DelegateHttpClient; |
| 18: | use Nexus\Mcp\Core\Auth\ResourceIdentifier; |
| 19: | use Nexus\Mcp\Core\Auth\ScopeSet; |
| 20: | use Nexus\Mcp\Core\Exception\RuntimeException; |
| 21: | use Psr\Log\LoggerInterface; |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | final readonly class GrantContext |
| 27: | { |
| 28: | |
| 29: | |
| 30: | |
| 31: | public function __construct( |
| 32: | public DiscoveredResource $discovered, |
| 33: | public ResourceIdentifier $resource, |
| 34: | public ScopeSet $scopes, |
| 35: | public AuthorizationOptions $options, |
| 36: | public DelegateHttpClient $httpClient, |
| 37: | public LoggerInterface $logger, |
| 38: | private ClientRegistrar $registrar, |
| 39: | private TokenEndpoint $tokenEndpoint, |
| 40: | ) { |
| 41: | } |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public function resolveRegistration(Cancellation $cancellation): ClientRegistration |
| 50: | { |
| 51: | return $this->registrar->resolve($this->discovered->server, $this->options, $cancellation); |
| 52: | } |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | public function requestToken( |
| 59: | ClientRegistration $registration, |
| 60: | array $parameters, |
| 61: | Cancellation $cancellation, |
| 62: | ?ScopeSet $requestedScopes = null, |
| 63: | ): AccessToken { |
| 64: | return $this->tokenEndpoint->requestToken( |
| 65: | $this->discovered->server, |
| 66: | $registration, |
| 67: | $parameters, |
| 68: | $requestedScopes ?? $this->scopes, |
| 69: | $cancellation, |
| 70: | ); |
| 71: | } |
| 72: | } |
| 73: | |