Documentation
¶
Overview ¶
Request authorization: verify the bearer, then ask mcp-auth for a credential-access assertion so revocation applies on the next request.
the resource-server SDK (auth-client/go/mcpauth).
For each request: verify the bearer token (signature, issuer, audience, expiry, scopes), then ask mcp-auth for a credential-access assertion. mcp-auth re-checks the resource client, the subject token and that the login session is still active, so revocation takes effect on the next request. Nothing is cached across requests. The assertion proves approval only; it contains no credentials.
Package credential is the shared credential gateway. It runs from the same image as the per-server gateway, in its own mode, as one workload for every server that opts in: mcp-auth sends the browser to its sign-in page for a resource, it validates and keeps the person's header values in memory, and on later requests it verifies the OAuth bearer against mcp-auth and adds those headers before forwarding to the upstream.
The sign-in half of the gateway. mcp-auth treats it as a plain OAuth 2.0 identity provider for one resource: it sends the browser to /login/authorize, later exchanges the code at /login/token and reads an opaque subject from /login/userinfo.
The person's header values go from the browser to this service only. They are validated at the upstream, kept in the gateway's memory, and never reach mcp-auth, which sees nothing but the opaque subject.
Package session binds upstream MCP session ids to the authenticated user and service.
The gateway returns "<upstream-id>.<tag>" to the client, where tag is an HMAC over (issuer, subject, service, upstream-id) under a deployment secret. A later request is accepted only if the tag verifies for its own verified identity and service, so a session id cannot be replayed by another user or against another service. The binding is stateless: it survives restarts and works across replicas that share the key.
Index ¶
- Constants
- Variables
- func LoginClientID(serviceID string) string
- func NewSubject() (string, error)
- func Run(path string) error
- func SubjectPrefix(serviceID string) string
- type Authorizer
- type Binder
- type Config
- type Failure
- type FormField
- type Gateway
- type Header
- type Identity
- type LoginConfig
- type LoginProvider
- type ResourceClient
- type Result
- type Service
- type Store
Constants ¶
const ( // AssertionType is the RFC 8693 token type of a credential-access assertion. AssertionType = "urn:mcp-auth:token-type:credential-access-assertion" // AssertionJWTType is the JOSE typ of the assertion. AssertionJWTType = "credential-access+jwt" )
Variables ¶
var ( ErrRejected = errors.New("upstream credential validation failed") )
ErrRejected means the upstream refused the credentials. ErrUnavailable means the upstream could not be asked. Neither carries upstream or credential text.
Functions ¶
func LoginClientID ¶
LoginClientID is the OAuth client id mcp-auth presents to a service's sign-in endpoints. The connector entry for the service must use it.
func NewSubject ¶
NewSubject returns an unguessable subject for one sign-in.
func Run ¶
Run serves the credential gateway described by the config file at path until the process is told to stop.
func SubjectPrefix ¶
SubjectPrefix is what mcp-auth puts before the opaque subject the service's sign-in returns. The login method for the service must use it as its subject_prefix, because the gateway stores values under the prefixed subject.
Types ¶
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
Authorizer authorises requests for every configured service.
func NewAuthorizer ¶
func NewAuthorizer(cfg *Config, metadataURL func(Service) string) *Authorizer
NewAuthorizer builds an Authorizer. metadataURL returns each service's protected-resource metadata URL.
type Binder ¶
type Binder struct {
// contains filtered or unexported fields
}
Binder wraps and unwraps session ids.
type Config ¶
type Config struct {
Listen string
Issuer string
TokenEndpoint string
JWKSURI string
AllowInsecureHTTP bool
ASTimeout time.Duration
PublicPathPrefix string
SessionKey []byte
FormTTL time.Duration
FormMaxEntries int
MaxRequestBytes int64
ConnectTimeout time.Duration
ResponseHeaderTimeout time.Duration
Services []Service
}
Config is the validated gateway configuration.
func LoadConfig ¶
LoadConfig reads and validates the configuration file at path.
func ParseConfig ¶
ParseConfig validates raw JSON configuration.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway implements http.Handler for every configured service.
type Header ¶
type Header struct{ Name, Field string }
Header says which stored field is sent as which upstream header.
type Identity ¶
type Identity struct{ Issuer, Subject string }
Identity is a verified (issuer, subject) pair.
type LoginConfig ¶
type LoginConfig struct {
// ClientID is the OAuth client id mcp-auth presents.
ClientID string
// Origin is this service's public origin, for the same-origin check.
Origin string
// BasePath is the public path /login/* lives under.
BasePath string
// CallbackURL is the only redirect_uri accepted: mcp-auth's identity callback.
CallbackURL string
// Fields are the inputs shown, in order.
Fields []FormField
// ServerName, Namespace and UpstreamHost are shown on the page so the
// person can see which server receives the values. They come from the
// operator-derived configuration.
ServerName, Namespace, UpstreamHost string
// Authenticate validates submitted values at the upstream and returns the
// opaque subject. It does not store them. It reports ErrRejected or ErrUnavailable.
Authenticate func(ctx context.Context, values map[string]string) (string, error)
// Commit stores values for subject. The page calls it only after this
// submission has won the pending request.
Commit func(subject string, values map[string]string) error
Now func() time.Time
}
LoginConfig describes one service's sign-in.
type LoginProvider ¶
type LoginProvider struct {
// contains filtered or unexported fields
}
LoginProvider serves the sign-in endpoints for one service.
func NewLoginProvider ¶
func NewLoginProvider(cfg LoginConfig) *LoginProvider
NewLoginProvider builds a provider.
func (*LoginProvider) ServeHTTP ¶
func (p *LoginProvider) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP expects the request path relative to BasePath: /login/<endpoint>.
type ResourceClient ¶
type ResourceClient struct {
ClientID string
KeyID string
PrivateKey *rsa.PrivateKey
}
ResourceClient is the gateway's identity at mcp-auth for one service.
type Service ¶
type Service struct {
ID string
ServerName string
Namespace string
ResourceURL string
ResourcePath string
UpstreamURL string
ValidationURL string
RequiredScopes []string
Client ResourceClient
FormFields []FormField
Headers []Header
}
Service is one proxied MCP backend.
type Store ¶
type Store struct {
TTL time.Duration
Max int
Now func() time.Time
// contains filtered or unexported fields
}
Store keeps the header values a person submitted at sign-in. Values live only in process memory, are bounded in count and lifetime, and are never logged. An entry is reachable only by the exact (issuer, subject, service) it was stored under, and the subject is a random value minted per sign-in.