[WIP] Add OAuth client_credentials grant for machine-to-machine auth#188
Open
[WIP] Add OAuth client_credentials grant for machine-to-machine auth#188
Conversation
Implements https://modelcontextprotocol.io/extensions/auth/oauth-client-credentials for non-interactive authentication in CI pipelines, service accounts, and other automation contexts. No browser required. Usage: mcpc login <server> --grant client-credentials \ --client-id <id> --client-secret <secret> \ [--scope "..."] [--token-endpoint <url>] mcpc persists client_id/client_secret in the OS keychain and re-issues access tokens automatically when they expire.
a11ee28 to
c5a661d
Compare
- Add mock OAuth endpoints to test server: /.well-known/oauth-authorization-server for discovery and /token for the client_credentials grant. Configurable via OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET, OAUTH_TOKEN env vars. - Auth check now validates the actual token value (not just presence of Bearer prefix). - New test suite (14 tests): login flow, profile metadata, session usage (tools-list, tools-call), --scope, --json output, validation errors, wrong credentials, credential leak check in --verbose, --help output. https://claude.ai/code/session_01E96muBqt36zJHubmGFUWfB
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.
Summary
--grant client-credentialstomcpc loginfor non-interactive M2M authentication (MCP extension spec)Usage
Changes
New files
src/lib/auth/client-credentials-flow.ts— discovers token endpoint, POSTsgrant_type=client_credentials, persists credentials + tokens to keychain, writes profile metadataModified files
src/lib/auth/oauth-utils.ts— newrequestClientCredentialsToken()functionsrc/lib/auth/oauth-token-manager.ts—grantTypeoption (refresh_token|client_credentials); re-issues tokens via client credentials when refresh token is absentsrc/lib/auth/token-refresh.ts— handlesauthType: 'oauth-client-credentials'profilessrc/lib/types.ts—AuthProfile.authTypeunion expanded;AuthCredentialsIPC extended withgrantType,clientSecret,scope,tokenEndpoint,accessTokenExpiresAtsrc/bridge/index.ts— bridge initializes token manager in client_credentials mode; persists re-issued tokens to keychainsrc/lib/bridge-manager.ts— forwards client secret, token endpoint, scope, and grant type to bridge via IPCsrc/lib/bridge-client.ts—sendAuthCredentialsnow uses theAuthCredentialstype directlysrc/cli/commands/auth.ts— routes--grant client-credentialsto the new flow; validates flag combinationssrc/cli/index.ts—--grantand--token-endpointoptions onlogincommand; updated help textsrc/cli/commands/sessions.ts— profile listing tags[client-credentials]profilesREADME.md— new "Machine-to-machine authentication" sectionCHANGELOG.md— entry under[Unreleased]Tests
test/unit/lib/auth/oauth-utils.test.ts— 4 new tests forrequestClientCredentialsToken()covering request body, scope, 401, and 5xx errorsTest plan
npm run buildpassesnpm run lintpassesnpm run test:unit— 536/536 tests passmcpc login --helpshows new--grantand--token-endpointoptionsmcpc login <url> --grant bogus→ clear errormcpc login <url> --grant client-credentialswithout--client-id/--client-secret→ clear errormcpc login <server> --grant client-credentials --client-id X --client-secret Yagainst a real OAuth serverhttps://claude.ai/code/session_01E96muBqt36zJHubmGFUWfB