Repository navigation
[Client] Add client ID metadata documents and a console authorization handler - #668
Merged
chr-hertel merged 3 commits intoNov 10, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The client ID URL guard accepts malformed URLs and forbidden components, which can cause authorization failures and need stricter validation with regression tests.
1 open issue
What changed in this PR
This extends the PHP SDK’s client authorization work from #666 with client ID metadata documents and a console handler for environments without a browser.
Changes:
- Adds metadata-document URLs as client IDs, with registration fallback when unsupported.
- Adds console authorization using the full redirected URL to preserve response checks.
- Expands authorization documentation and tests, including conformance coverage and Keycloak integration.
| File | Description |
|---|---|
tests/Unit/Client/Transport/HttpTransportTest.php |
Tests credentials and authorization failure handling. |
tests/Unit/Client/Auth/TokenEndpointTest.php |
Tests token authentication and error responses. |
tests/Unit/Client/Auth/TokenEndpointAuthMethodTest.php |
Tests authentication-method negotiation. |
tests/Unit/Client/Auth/ProtectedResourceMetadataTest.php |
Tests resource URL boundaries. |
tests/Unit/Client/Auth/PkceTest.php |
Tests PKCE generation and reconstruction. |
tests/Unit/Client/Auth/OAuthTest.php |
Tests builder settings and metadata URL validation. |
tests/Unit/Client/Auth/MetadataDiscoveryTest.php |
Tests discovery locations and issuer checks. |
tests/Unit/Client/Auth/FileCredentialStorageTest.php |
Tests credential persistence and permissions. |
tests/Unit/Client/Auth/ClientRegistrationTest.php |
Tests registration requests and responses. |
tests/Unit/Client/Auth/AuthorizationServerMetadataTest.php |
Tests metadata parsing and endpoint validation. |
tests/Unit/Client/Auth/AuthorizationHandlerTest.php |
Tests loopback and console handlers. |
tests/Unit/Client/Auth/AuthorizationChallengeTest.php |
Tests Bearer challenge parsing. |
tests/Unit/Client/Auth/AuthenticatingHttpClientTest.php |
Tests retries, body replay and response cleanup. |
tests/Unit/Client/Auth/AccessTokenTest.php |
Tests token expiry, scopes and serialization. |
tests/Integration/Fixture/oauth/resource-server.php |
Provides a protected MCP test server. |
tests/Integration/Fixture/oauth/authorization-server.php |
Provides registration and PKCE test endpoints. |
tests/Integration/ClientOAuthTest.php |
Exercises authorization over real HTTP. |
tests/E2E/server.php |
Validates Keycloak tokens before serving MCP. |
tests/E2E/run.sh |
Runs the container-based authorization suite. |
tests/E2E/README.md |
Documents the end-to-end setup. |
tests/E2E/nginx.conf |
Routes requests to the protected server. |
tests/E2E/keycloak/realm.json |
Defines the test realm and token audience. |
tests/E2E/docker-compose.yml |
Configures Keycloak and MCP containers. |
tests/E2E/client.php |
Checks protected access and credential reuse. |
tests/E2E/BrowserAuthorizationHandler.php |
Automates login for end-to-end tests. |
tests/Conformance/conformance-baseline-2026-07-28.yml |
Removes covered authorization exceptions. |
tests/Conformance/conformance-baseline-2025-11-25.yml |
Removes covered cases; retains machine-grant exceptions. |
tests/Conformance/client.php |
Configures OAuth and metadata-document scenarios. |
src/Exception/AuthorizationException.php |
Defines client authorization failures. |
src/Client/Transport/HttpTransport.php |
Integrates authentication and refusal handling. |
src/Client/Auth/TokenEndpointAuthMethod.php |
Selects token endpoint authentication methods. |
src/Client/Auth/TokenEndpoint.php |
Exchanges credentials for access tokens. |
src/Client/Auth/ProtectedResourceMetadata.php |
Parses resource metadata and checks URL coverage. |
src/Client/Auth/Pkce.php |
Generates PKCE verifiers and challenges. |
src/Client/Auth/OAuthConfiguration.php |
Holds application authorization settings. |
src/Client/Auth/OAuth.php |
Builds OAuth authentication, including metadata URLs. |
src/Client/Auth/MetadataDiscovery.php |
Discovers resource and authorization metadata. |
src/Client/Auth/LoopbackAuthorizationHandler.php |
Opens a browser and receives callbacks. |
src/Client/Auth/InMemoryCredentialStorage.php |
Stores credentials for the process lifetime. |
src/Client/Auth/HeadlessAuthorizationHandler.php |
Reads redirects without interactive login. |
src/Client/Auth/Grant.php |
Defines supported OAuth grant types. |
src/Client/Auth/FileCredentialStorage.php |
Persists credentials in private files. |
src/Client/Auth/CredentialStorageInterface.php |
Defines credential storage operations. |
src/Client/Auth/ConsoleAuthorizationHandler.php |
Prompts for the full redirected URL. |
src/Client/Auth/ClientRegistration.php |
Represents client identity and credentials. |
src/Client/Auth/ClientRegistrar.php |
Performs dynamic client registration. |
src/Client/Auth/ClientMetadata.php |
Serializes client registration metadata. |
src/Client/Auth/BearerToken.php |
Attaches an existing bearer token. |
src/Client/Auth/AuthorizationServerMetadata.php |
Parses authorization server capabilities. |
src/Client/Auth/AuthorizationHandlerInterface.php |
Defines authorization interaction handlers. |
src/Client/Auth/AuthorizationChallenge.php |
Extracts Bearer challenge parameters. |
src/Client/Auth/AuthenticatorInterface.php |
Defines authentication and challenge handling. |
src/Client/Auth/AuthenticatingHttpClient.php |
Adds authentication and bounded retries. |
src/Client/Auth/AccessToken.php |
Represents tokens, expiry and granted scopes. |
src/Client.php |
Documents authorization exceptions on client operations. |
mkdocs.yml |
Adds authorization to documentation navigation. |
Makefile |
Adds the end-to-end test target. |
examples/client/README.md |
Introduces the OAuth client example. |
examples/client/oauth_client.php |
Demonstrates authorization with stored credentials. |
docs/examples.md |
Links the OAuth example. |
docs/client/transports.md |
Documents transport authentication options. |
docs/client/index.md |
Links the authorization guide. |
docs/client/errors.md |
Explains authorization exception handling. |
docs/client/authorization.md |
Documents OAuth setup, handlers and safeguards. |
CHANGELOG.md |
Records authorization features and exception changes. |
.gitignore |
Excludes credentials and generated test artifacts. |
.github/workflows/pipeline.yaml |
Adds the authorization end-to-end job. |
Review effort: Balanced
chr-hertel
force-pushed
the
client-auth-identity
branch
from
November 8, 2026 12:09
8f43219 to
dbdffb7
Compare
chr-hertel
force-pushed
the
client-auth-identity
branch
from
November 9, 2026 01:50
dbdffb7 to
40cdcd7
Compare
… handler setClientMetadataUrl() uses a published document as the client id where the authorization server supports it, and otherwise registers as before. The URL has to be https with a path. ConsoleAuthorizationHandler prints the authorization URL and reads back the redirected URL, for a shell without a browser. It refuses a bare code, which would skip the state and iss checks.
chr-hertel
force-pushed
the
client-auth-identity
branch
from
November 9, 2026 23:32
40cdcd7 to
42b990c
Compare
chr-hertel
marked this pull request as ready for review
November 9, 2026 23:41
chr-hertel
requested review from
CodeWithKyrian,
Nyholm and
soyuka
as code owners
November 9, 2026 23:41
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fourth slice of the client authorization in chr-hertel#53. Follows #666.
setClientMetadataUrl()uses a client ID metadata document as the client id where the authorization server supports it, otherwise the client registers as before. The URL needs https & a path, same check as the TypeScript SDK.ConsoleAuthorizationHandlerfor a remote shell or a container without a browser. It wants the whole redirected URL and refuses a bare code, which would skip thestate&isschecks.The
issrule of #666 for an authorization endpoint on another origin applies with a metadata document as well.auth/basic-cimdleaves both conformance baselines with this. Machine grants come next.