mcpauthsvc

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 27 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 mcpauthsvc owns Core's deployment-local MCP OAuth decisions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidClient  = xerror.New(xerror.KindInvalidInput, "MCP_OAUTH_INVALID_CLIENT", "OAuth client was rejected")
	ErrInvalidTarget  = xerror.New(xerror.KindInvalidInput, "MCP_OAUTH_INVALID_TARGET", "OAuth resource was rejected")
	ErrInvalidRequest = xerror.New(xerror.KindInvalidInput, "MCP_OAUTH_INVALID_REQUEST", "OAuth request was rejected")
	ErrInvalidGrant   = xerror.New(xerror.KindInvalidInput, "MCP_OAUTH_INVALID_GRANT", "OAuth grant was rejected")
)
View Source
var ErrInvalidAccessToken = xerror.New(xerror.KindUnauthorized, "MCP_OAUTH_INVALID_TOKEN", "OAuth access token was rejected")
View Source
var ErrInvalidMachineAdminSession = xerror.New(xerror.KindForbidden, "MCP_MACHINE_ADMIN_SESSION_REQUIRED", "Machine client management requires a valid browser session")

Functions

This section is empty.

Types

type AuthorizationRequest

type AuthorizationRequest struct {
	ClientID, RedirectURI, Resource, ResponseType, Challenge, ChallengeMethod string
}

type BrowserIdentity

type BrowserIdentity struct {
	User, Organization    slug.Slug
	SessionID             string
	AuthenticationVersion int64
	AuthenticatedAt       time.Time
}

type Client

type Client struct {
	ID           string
	Name         string
	RedirectURIs []string
}

type CodeBinding

type CodeBinding struct {
	// contains filtered or unexported fields
}

CodeBinding is the validated protocol state to store with an approved code.

type CodeRedemption

type CodeRedemption struct {
	Code, ClientID, RedirectURI, Resource, Verifier string
}

type ConsentDecision

type ConsentDecision string
const (
	ConsentDeny      ConsentDecision = "deny"
	ConsentReadOnly  ConsentDecision = "read_only"
	ConsentReadWrite ConsentDecision = "read_write"
)

type Deployment

type Deployment struct {
	// contains filtered or unexported fields
}

func New

func New(issuer, resource string, clients []Client) (*Deployment, error)

New uses deployment configuration for issuer and audience. Both URLs require HTTPS.

func (*Deployment) AcceptsResource

func (d *Deployment) AcceptsResource(raw string) bool

AcceptsResource compares the full deployment resource, folding scheme and host only.

func (*Deployment) IssuerDiscovery

func (d *Deployment) IssuerDiscovery() (string, IssuerMetadata)

func (*Deployment) ProtectedResourceDiscovery

func (d *Deployment) ProtectedResourceDiscovery() (string, ProtectedResourceMetadata)

func (*Deployment) ValidateAuthorization

func (d *Deployment) ValidateAuthorization(ctx context.Context, request AuthorizationRequest) (Client, CodeBinding, error)

ValidateAuthorization checks protocol inputs before consent or code issuance.

func (*Deployment) ValidateCodeExchange

func (d *Deployment) ValidateCodeExchange(binding CodeBinding, clientID, redirectURI, resource, verifier string) error

ValidateCodeExchange checks the binding loaded from trusted code storage. The caller must check expiry and consume that code atomically with issuance.

type IssuerMetadata

type IssuerMetadata struct {
	Issuer                               string   `json:"issuer"`
	AuthorizationEndpoint                string   `json:"authorization_endpoint"`
	TokenEndpoint                        string   `json:"token_endpoint"`
	RevocationEndpoint                   string   `json:"revocation_endpoint"`
	ResponseTypes                        []string `json:"response_types_supported"`
	GrantTypes                           []string `json:"grant_types_supported"`
	TokenEndpointAuthMethods             []string `json:"token_endpoint_auth_methods_supported"`
	RevocationAuthMethods                []string `json:"revocation_endpoint_auth_methods_supported"`
	CodeChallengeMethods                 []string `json:"code_challenge_methods_supported"`
	ClientIDMetadataSupported            bool     `json:"client_id_metadata_document_supported"`
	AuthorizationResponseIssuerSupported bool     `json:"authorization_response_iss_parameter_supported"`
}

type MachineAdminRequest

type MachineAdminRequest struct {
	Browser              BrowserIdentity
	Organization, APIKey slug.Slug
}

type MachineAdministration

type MachineAdministration struct {
	// contains filtered or unexported fields
}

func NewMachineAdministration

func NewMachineAdministration(tokens *TokenService, audit workerproducer.EventProducer) (*MachineAdministration, error)

func (*MachineAdministration) Disconnect

func (a *MachineAdministration) Disconnect(ctx context.Context, request MachineAdminRequest, clientID string) error

Disconnect only changes a registration attached to the key authorized by the caller.

func (*MachineAdministration) Register

Register rechecks browser proof and records required audit evidence in the same transaction as registration. The caller authorizes the exact API key.

type MachineClientCredentials

type MachineClientCredentials struct {
	ClientID, ClientSecret string
}

type MachineRegistration

type MachineRegistration struct {
	MachineClientCredentials
	ExpiresAt time.Time
}

type ProtectedResourceMetadata

type ProtectedResourceMetadata struct {
	Resource             string   `json:"resource"`
	AuthorizationServers []string `json:"authorization_servers"`
	BearerMethods        []string `json:"bearer_methods_supported"`
}

type TokenPair

type TokenPair struct {
	AccessToken, RefreshToken string
	AccessExpiresAt           time.Time
}

type TokenService

type TokenService struct {
	// contains filtered or unexported fields
}

func NewTokenService

func NewTokenService(deployment *Deployment, txm postgres.TransactionManager) (*TokenService, error)

func (*TokenService) AuthenticateDelegatedRequest

func (s *TokenService) AuthenticateDelegatedRequest(ctx context.Context, token, resource string, org slug.Slug) (context.Context, authorization.DelegatedPrincipal, error)

AuthenticateDelegatedRequest returns the principal and the context to use for every authorization check and database operation on this request.

func (*TokenService) AuthenticateMachineAccessToken

func (s *TokenService) AuthenticateMachineAccessToken(ctx context.Context, raw, resource string, organization slug.Slug) (mcpauth.MachinePrincipal, error)

func (*TokenService) AuthenticateUserAccessToken

func (s *TokenService) AuthenticateUserAccessToken(ctx context.Context, raw, resource string, organization slug.Slug) (mcpauth.UserPrincipal, error)

AuthenticateUserAccessToken returns an identity for the exact operation tenant. The caller still needs a scoped authorization decision for the operation.

func (*TokenService) BeginUserConsent

func (s *TokenService) BeginUserConsent(ctx context.Context, request AuthorizationRequest, state string, browser BrowserIdentity) (model.MCPConsentPrompt, error)

BeginUserConsent pins the verified identity before returning a one-use browser prompt.

func (*TokenService) CompleteUserConsent

func (s *TokenService) CompleteUserConsent(ctx context.Context, nonce string, browser BrowserIdentity, decision ConsentDecision) (string, error)

CompleteUserConsent consumes the prompt and issues a code in the same transaction. The browser boundary must validate CSRF before calling it.

func (*TokenService) Deployment

func (s *TokenService) Deployment() *Deployment

func (*TokenService) DisconnectMachineClient

func (s *TokenService) DisconnectMachineClient(ctx context.Context, organization, key slug.Slug, clientID string) error

DisconnectMachineClient requires authorization to administer the selected organization.

func (*TokenService) DisconnectUserClient

func (s *TokenService) DisconnectUserClient(ctx context.Context, browser BrowserIdentity, clientID string) error

DisconnectUserClient revokes every grant for this client in the browser's current scope.

func (*TokenService) IssueMachineTokens

func (s *TokenService) IssueMachineTokens(ctx context.Context, credentials MachineClientCredentials, resource string) (TokenPair, error)

IssueMachineTokens authenticates a pre-registered confidential client scoped to one API key.

func (*TokenService) ListUserClients

func (s *TokenService) ListUserClients(ctx context.Context, browser BrowserIdentity, after string) ([]string, string, error)

ListUserClients returns approved clients in the browser's current scope.

func (*TokenService) RedeemUserCode

func (s *TokenService) RedeemUserCode(ctx context.Context, request CodeRedemption) (TokenPair, error)

func (*TokenService) RegisterMachineClient

func (s *TokenService) RegisterMachineClient(ctx context.Context, organization, key slug.Slug) (MachineRegistration, error)

RegisterMachineClient requires an authorized administrator's approval of the exact organization key.

func (*TokenService) RejectUnsupportedUserScope

func (s *TokenService) RejectUnsupportedUserScope(ctx context.Context, request AuthorizationRequest, state string) (string, error)

RejectUnsupportedUserScope sends the error only to a verified client redirect.

func (*TokenService) RevokeMachineToken

func (s *TokenService) RevokeMachineToken(ctx context.Context, credentials MachineClientCredentials, raw, resource string) error

func (*TokenService) RevokeUserToken

func (s *TokenService) RevokeUserToken(ctx context.Context, raw, clientID, resource string) error

RevokeUserToken accepts an access or refresh credential and revokes its entire grant.

func (*TokenService) RotateMachineRefreshToken

func (s *TokenService) RotateMachineRefreshToken(ctx context.Context, credentials MachineClientCredentials, token, resource string) (TokenPair, error)

func (*TokenService) RotateUserRefreshToken

func (s *TokenService) RotateUserRefreshToken(ctx context.Context, token, clientID, resource string) (TokenPair, error)

Jump to

Keyboard shortcuts

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