MCP PHP SDK

LoopbackAuthorizationHandler implements AuthorizationHandlerInterface

FinalYes

Opens the user's browser and catches the redirect on a loopback listener.

Tags
author

Christopher Hertel mail@christopher-hertel.de

Table of Contents

Interfaces

AuthorizationHandlerInterface
Takes the user to the authorization endpoint and returns the answer of the authorization server.

Constants

CALLBACK_PAGE  : mixed = '<!doctype html><meta charset="utf-8"><title>Au...

Properties

$logger  : LoggerInterface
$openBrowser  : mixed
$timeout  : int

Methods

__construct()  : mixed
authorize()  : array<string, string>
Send the user to $authorizationUrl and return the query parameters of the redirect to $redirectUri, unchecked.
isPortInUse()  : bool
open()  : void
serve()  : array<string, string>|null
Answer one connection, and return its query parameters only for the callback, as anyone local can connect.

Constants

CALLBACK_PAGE

private mixed CALLBACK_PAGE = '<!doctype html><meta charset="utf-8"><title>Authorization finished</title>' . '<body style="font:16px system-ui;margin:4rem auto;max-width:32rem">' . '<h1>Authorization finished.</h1><p>You can close this tab and return to the application.</p>'

Properties

Methods

__construct()

public __construct([callable(string $url): void|null $openBrowser = null ][, int $timeout = 300 ][, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
$openBrowser : callable(string $url): void|null = null

how to put the URL in front of the user, defaulting to the platform's URL opener

$timeout : int = 300

seconds to wait for the user to come back

$logger : LoggerInterface = new NullLogger()

authorize()

Send the user to $authorizationUrl and return the query parameters of the redirect to $redirectUri, unchecked.

public authorize(string $authorizationUrl, string $redirectUri) : array<string, string>
Parameters
$authorizationUrl : string
$redirectUri : string
Return values
array<string, string> —

the callback's query parameters

isPortInUse()

private static isPortInUse(string $host, int $port) : bool
Parameters
$host : string
$port : int
Return values
bool

serve()

Answer one connection, and return its query parameters only for the callback, as anyone local can connect.

private serve(resource $connection, string $callbackPath, string|null $state) : array<string, string>|null
Parameters
$connection : resource
$callbackPath : string
$state : string|null
Return values
array<string, string>|null
On this page

Search results