oauthrs

package
v1.1.975 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
var ErrJWKSUnavailable = errors.New("JWKS unavailable")

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL