go-sdk/auth
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ravish Gupta 2e21834ad3
extauth: add ClientCredentialsHandler for OAuth client credentials grant (#895)
## Summary

- Add `ClientCredentialsHandler` implementing `auth.OAuthHandler` using
the OAuth 2.0 Client Credentials grant (RFC 6749 Section 4.4) for
service-to-service authentication with pre-registered credentials.
- Bypasses both dynamic client registration and the authorization code
flow — the handler takes a client ID + secret directly and exchanges
them at the token endpoint.
- Supports two modes: direct `TokenEndpoint` URL, or metadata discovery
via `AuthServerURL` (RFC 8414).
- Add `client_credentials` grant type support to the fake authorization
server in `internal/oauthtest` for testing.

## Context

Per @jba's [comment on
#627](https://github.com/modelcontextprotocol/go-sdk/issues/627#issuecomment-3640982691):

> Our default implementation for that framework should support client ID
and client secret as options, to handle that variant. [...] If those are
set, our implementation would bypass dynamic client reservation. That is
just a couple of lines of code, I believe.

The client-side OAuth scaffolding (#785) that this was blocked on is now
complete, as @brkane noted.

Implements the client credentials variant of
[SEP-1046](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1046).
The JWT Assertions variant (RFC 7523) is left for a follow-up as its API
surface needs more design discussion.

## Test plan

- [x] `TestNewClientCredentialsHandler_Validation` — validates all
config error cases (nil config, missing fields, mutual exclusivity)
- [x] `TestClientCredentialsHandler_Authorize/direct_token_endpoint` —
end-to-end with fake auth server
- [x] `TestClientCredentialsHandler_Authorize/metadata_discovery` —
discovers token endpoint via RFC 8414 metadata
- [x] `TestClientCredentialsHandler_Authorize/bad_credentials` —
verifies failure with wrong secret
- [x] `go test ./... -count=1` passes
- [x] `go vet ./...` clean

Refs #627

Co-authored-by: Maciej Kisiel <mkisiel@google.com>
2026-04-27 13:28:35 +02:00
..
extauth extauth: add ClientCredentialsHandler for OAuth client credentials grant (#895) 2026-04-27 13:28:35 +02:00
auth.go auth: return scope in WWW-Authenticate header. (#834) 2026-03-17 16:34:10 +01:00
auth_test.go auth: return scope in WWW-Authenticate header. (#834) 2026-03-17 16:34:10 +01:00
authorization_code.go feat: add automatic application_type inference (#904) 2026-04-27 13:02:01 +02:00
authorization_code_test.go feat: add automatic application_type inference (#904) 2026-04-27 13:02:01 +02:00
client.go Enterprise managed authorization (#770) 2026-03-30 16:29:30 +02:00
shared.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00
shared_test.go all: stabilize client OAuth support (#861) 2026-03-31 12:36:31 +02:00