MCP PHP SDK

OidcDiscovery implements OidcDiscoveryInterface

Discovers OAuth 2.0 / OpenID Connect authorization server metadata.

Supports:

  • OAuth 2.0 Authorization Server Metadata (RFC 8414)
  • OpenID Connect Discovery 1.0
Tags
see
https://datatracker.ietf.org/doc/html/rfc8414
see
https://openid.net/specs/openid-connect-discovery-1_0.html
author

Volodymyr Panivko sveneld300@gmail.com

Table of Contents

Interfaces

OidcDiscoveryInterface
Contract for resolving OAuth/OIDC endpoint metadata from an issuer.

Constants

CACHE_KEY_PREFIX  = 'mcp_oidc_discovery_'

Properties

$cache  : CacheInterface|null
$cacheTtl  : int
$httpClient  : ClientInterface
$metadataPolicy  : OidcDiscoveryMetadataPolicyInterface
$requestFactory  : RequestFactoryInterface

Methods

__construct()  : mixed
discover()  : array<string, mixed>
Discovers authorization server metadata from the issuer URL.
getAuthorizationEndpoint()  : string
Gets the authorization endpoint from the authorization server metadata.
getJwksUri()  : string
Gets the JWKS URI from the authorization server metadata.
getTokenEndpoint()  : string
Gets the token endpoint from the authorization server metadata.
fetchJson()  : array<string, mixed>
fetchMetadata()  : array<string, mixed>

Constants

CACHE_KEY_PREFIX

private mixed CACHE_KEY_PREFIX = 'mcp_oidc_discovery_'

Properties

$requestFactory

private RequestFactoryInterface $requestFactory

Methods

__construct()

public __construct([ClientInterface|null $httpClient = null ][, RequestFactoryInterface|null $requestFactory = null ][, CacheInterface|null $cache = null ][, int $cacheTtl = 3600 ][, OidcDiscoveryMetadataPolicyInterface|null $metadataPolicy = null ]) : mixed
Parameters
$httpClient : ClientInterface|null = null

PSR-18 HTTP client (auto-discovered if null)

$requestFactory : RequestFactoryInterface|null = null

PSR-17 request factory (auto-discovered if null)

$cache : CacheInterface|null = null

PSR-16 cache for metadata (optional)

$cacheTtl : int = 3600

Cache TTL in seconds (default: 1 hour)

$metadataPolicy : OidcDiscoveryMetadataPolicyInterface|null = null

Metadata validation policy

discover()

Discovers authorization server metadata from the issuer URL.

public discover(string $issuer) : array<string, mixed>

Tries endpoints in priority order per RFC 8414 and OpenID Connect Discovery:

  1. OAuth 2.0 path insertion: /.well-known/oauth-authorization-server/{path}
  2. OIDC path insertion: /.well-known/openid-configuration/{path}
  3. OIDC path appending: {path}/.well-known/openid-configuration
Parameters
$issuer : string

The issuer URL (e.g., "https://auth.example.com/realms/mcp")

Tags
throws
RuntimeException

If discovery fails

Return values
array<string, mixed>

The authorization server metadata

getAuthorizationEndpoint()

Gets the authorization endpoint from the authorization server metadata.

public getAuthorizationEndpoint(string $issuer) : string
Parameters
$issuer : string

The issuer URL

Tags
throws
RuntimeException

If discover fails

Return values
string

The authorization endpoint URL

getJwksUri()

Gets the JWKS URI from the authorization server metadata.

public getJwksUri(string $issuer) : string
Parameters
$issuer : string

The issuer URL

Tags
throws
RuntimeException

If discover fails

Return values
string

The JWKS URI

getTokenEndpoint()

Gets the token endpoint from the authorization server metadata.

public getTokenEndpoint(string $issuer) : string
Parameters
$issuer : string

The issuer URL

Tags
throws
RuntimeException

If discover fails

Return values
string

The token endpoint URL

fetchJson()

private fetchJson(string $url) : array<string, mixed>
Parameters
$url : string
Return values
array<string, mixed>

fetchMetadata()

private fetchMetadata(string $issuer) : array<string, mixed>
Parameters
$issuer : string
Return values
array<string, mixed>

        
On this page

Search results