Documentation
¶
Overview ¶
Package oauthrs provides an opt-in OAuth JWT resource-server boundary for MCP HTTP handlers. It verifies locally signed access tokens using a preconfigured issuer and JWKS endpoint; it does not acquire tokens, perform introspection, or provide revocation, DPoP, or mTLS-bound token checks. Callers remain responsible for serving the protected endpoint over HTTPS.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrJWKSUnavailable identifies a failure to obtain or use the configured JWKS document. The MCP SDK middleware maps it to a server error, not a 401.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Issuer string
Audience string
Resource string
JWKSURL string
MetadataURL string
Scopes []string
Algorithms []string
// CacheTTL defaults to five minutes and, when set, must be between
// ten seconds and one hour.
CacheTTL time.Duration
// ClockSkew defaults to zero and cannot exceed two minutes.
ClockSkew time.Duration
HTTPClient *http.Client
}
Config contains trusted resource-server settings. Issuer, Audience, Resource, JWKSURL, MetadataURL, Scopes, and Algorithms must be configured explicitly. Only HTTPS URLs are accepted. HTTPClient may provide a custom trust store for private authorization servers, but redirects are always disabled.
type ResourceServer ¶
type ResourceServer struct {
// contains filtered or unexported fields
}
ResourceServer holds immutable verification settings and a synchronized JWKS cache. Construct it with New before publishing its handlers.
func NewResourceServer ¶
func NewResourceServer(config Config) (*ResourceServer, error)
NewResourceServer validates configuration and returns a fail-closed resource-server verifier.
func (*ResourceServer) Middleware ¶
func (rs *ResourceServer) Middleware(next http.Handler) http.Handler
Middleware verifies every bearer token and applies the configured scope and expiration requirements using the MCP SDK's OAuth middleware.
func (*ResourceServer) ProtectedResourceMetadataHandler ¶
func (rs *ResourceServer) ProtectedResourceMetadataHandler() http.Handler
ProtectedResourceMetadataHandler serves RFC 9728 metadata for this resource. Mount it at the resource metadata URL configured in Config.