Documentation
¶
Overview ¶
Package mcpauthsvc owns Core's deployment-local MCP OAuth decisions.
Index ¶
- Variables
- type AuthorizationRequest
- type BrowserIdentity
- type Client
- type CodeBinding
- type CodeRedemption
- type ConsentDecision
- type Deployment
- func (d *Deployment) AcceptsResource(raw string) bool
- func (d *Deployment) IssuerDiscovery() (string, IssuerMetadata)
- func (d *Deployment) ProtectedResourceDiscovery() (string, ProtectedResourceMetadata)
- func (d *Deployment) ValidateAuthorization(ctx context.Context, request AuthorizationRequest) (Client, CodeBinding, error)
- func (d *Deployment) ValidateCodeExchange(binding CodeBinding, clientID, redirectURI, resource, verifier string) error
- type IssuerMetadata
- type MachineAdminRequest
- type MachineAdministration
- type MachineClientCredentials
- type MachineRegistration
- type ProtectedResourceMetadata
- type TokenPair
- type TokenService
- func (s *TokenService) AuthenticateDelegatedRequest(ctx context.Context, token, resource string, org slug.Slug) (context.Context, authorization.DelegatedPrincipal, error)
- func (s *TokenService) AuthenticateMachineAccessToken(ctx context.Context, raw, resource string, organization slug.Slug) (mcpauth.MachinePrincipal, error)
- func (s *TokenService) AuthenticateUserAccessToken(ctx context.Context, raw, resource string, organization slug.Slug) (mcpauth.UserPrincipal, error)
- func (s *TokenService) BeginUserConsent(ctx context.Context, request AuthorizationRequest, state string, ...) (model.MCPConsentPrompt, error)
- func (s *TokenService) CompleteUserConsent(ctx context.Context, nonce string, browser BrowserIdentity, ...) (string, error)
- func (s *TokenService) Deployment() *Deployment
- func (s *TokenService) DisconnectMachineClient(ctx context.Context, organization, key slug.Slug, clientID string) error
- func (s *TokenService) DisconnectUserClient(ctx context.Context, browser BrowserIdentity, clientID string) error
- func (s *TokenService) IssueMachineTokens(ctx context.Context, credentials MachineClientCredentials, resource string) (TokenPair, error)
- func (s *TokenService) ListUserClients(ctx context.Context, browser BrowserIdentity, after string) ([]string, string, error)
- func (s *TokenService) RedeemUserCode(ctx context.Context, request CodeRedemption) (TokenPair, error)
- func (s *TokenService) RegisterMachineClient(ctx context.Context, organization, key slug.Slug) (MachineRegistration, error)
- func (s *TokenService) RejectUnsupportedUserScope(ctx context.Context, request AuthorizationRequest, state string) (string, error)
- func (s *TokenService) RevokeMachineToken(ctx context.Context, credentials MachineClientCredentials, ...) error
- func (s *TokenService) RevokeUserToken(ctx context.Context, raw, clientID, resource string) error
- func (s *TokenService) RotateMachineRefreshToken(ctx context.Context, credentials MachineClientCredentials, ...) (TokenPair, error)
- func (s *TokenService) RotateUserRefreshToken(ctx context.Context, token, clientID, resource string) (TokenPair, error)
Constants ¶
This section is empty.
Variables ¶
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") )
var ErrInvalidAccessToken = xerror.New(xerror.KindUnauthorized, "MCP_OAUTH_INVALID_TOKEN", "OAuth access token was rejected")
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 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 ¶
func (a *MachineAdministration) Register(ctx context.Context, request MachineAdminRequest) (MachineRegistration, error)
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 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)