oauth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 28 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 oauth is the gatekeeper's OAuth 2.1 authorization server for MCP connectors (docs/security/G4.md): the metadata documents, dynamic client registration and client ID metadata documents, authorize with its in-memory transactions, the consent API the admin SPA calls, token, revoke, and core.TokenValidator for the MCP access check.

One issuer at the application's root serves every resource, and a token is bound to one resource. The authorize request names the resource with the RFC 8707 resource <public URL><Paths.Path(id)> (Family Hub, with core.PerResource: <public URL>/mcp/<id>; with core.SingleResource: <public URL>/mcp), or, without one, with the scope mcp:<id>; the consent makes a grant of (person, client, resource); the validator refuses the token for any other resource.

The rules: only ChatGPT's and Claude's callbacks are accepted and they tell the assistant, PKCE S256 is required, every secret, code and token is kept only as its sha256, and a refresh token is spent on use, so one that comes back revokes its whole family.

A person acts only while core.Person.Active: the consent API, the code exchange and the refresh refuse anyone disabled or past the end of their term (Person.AccessUntil), and an access token never outlives that end. The grant itself stays, so a term the owner extends gives the person their connections back.

The package came from Family Hub's internal/oauth. What it sends to the assistants and the SPA is byte-for-byte what Family Hub sent, its wording included, except the one rename of the consent view (docs/security/G4.md, "Compatibility"). The texts name a resource and the application by Brand.ResourceWord and Brand.AppWord, whose defaults are Family Hub's "module" and "hub".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResourceMetadataURL

func ResourceMetadataURL(publicURL string, paths core.ResourcePaths, id core.ResourceID) string

ResourceMetadataURL is where the protected-resource metadata of id is served: the well-known between the public URL and the resource's MCP path (RFC 9728 §3.1; Family Hub: <public URL>/.well-known/oauth-protected-resource/mcp/<id>). The MCP access check names it in the WWW-Authenticate of a 401.

func ResourceURL

func ResourceURL(publicURL string, paths core.ResourcePaths, id core.ResourceID) string

ResourceURL is the RFC 8707 resource of id: its MCP URL, the public URL followed by paths.Path(id) (Family Hub: <public URL>/mcp/<id>).

Types

type Options

type Options struct {
	// Site.PublicURL is the issuer: https://<host> without a path (http only on a loopback host). Site.ClientIP says
	// where the client address of the rate limits and the audit comes from. New refuses a Site that fails
	// Site.Validate, an empty or unknown ClientIP mode included.
	Site core.Site
	// Brand.TxnCookie names the cookie that binds a consent to the browser that started it; Brand.Product titles the
	// error pages and gives the realm of a Basic challenge ("Family Hub": realm="family-hub"); Brand.ResourceWord and
	// Brand.AppWord are the words of the error texts ("module" and "hub" by default).
	Brand core.Brand
	Store store.Store
	// Sessions resolves the signed-in person of the consent API (package auth).
	Sessions core.Sessions
	// Catalog says which resources can be connected and by which accounts. A resource id must match
	// ^[a-z][a-z0-9-]{1,30}$ (Family Hub's module ids; Homie's "home").
	Catalog core.ResourceCatalog
	// Paths maps resources to their MCP paths (Family Hub: core.PerResource{Prefix: "/mcp/"}); a resource's URL is
	// Site.PublicURL + Paths.Path(id).
	Paths  core.ResourcePaths
	Logger *slog.Logger // nil: discard
	Clock  core.Clock   // nil: the system clock in UTC

	// ConsentStepUpOff makes approving a new grant one click. By default it needs a fresh step-up (a sign-in counts
	// for 5 minutes); reconnecting an existing grant is one click either way. Family Hub: FH_CONSENT_STEPUP=off.
	ConsentStepUpOff bool
	// TxnBindingOff stops binding an authorize transaction to the browser that started it. Only for an assistant
	// window that loses the cookie. Family Hub: FH_OAUTH_TXN_BINDING=off.
	TxnBindingOff bool
	// RefuseConnectorCallback refuses ChatGPT's per-connector callback /connector/oauth/<id>, which closes the
	// mix-up of T2.R H1. Family Hub: FH_OAUTH_CONNECTOR_CALLBACK=refuse.
	RefuseConnectorCallback bool
}

Options are the dependencies and switches of New.

type Server

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

Server is the authorization server. It serves the OAuth routes and the consent API (core.RouteRegistrar) and implements core.TokenValidator for the MCP access check.

func New

func New(o Options) (*Server, error)

New returns the authorization server of o.Site; its issuer is the public URL. It fetches client ID metadata documents over HTTPS from the assistants' hosts only.

func (*Server) RegisterRoutes

func (s *Server) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes adds the OAuth routes to mux: the metadata, register, authorize, token and revoke for the assistants, and the consent API for the SPA.

func (*Server) RevokeGrant

func (s *Server) RevokeGrant(ctx context.Context, id core.GrantID, actor core.PersonID, ip string) error

RevokeGrant revokes grant id with every token of it and audits oauth.grant.revoke, by actor from ip. The caller has checked that actor may (the connections API of package people). A revoked grant is left as it is; an unknown one is core.ErrNotFound.

func (*Server) ValidateAccess

func (s *Server) ValidateAccess(ctx context.Context, token string, r core.ResourceID) (core.AccessInfo, error)

ValidateAccess implements core.TokenValidator. token must be a live access token, found by its sha256, whose grant is active, younger than grantTTL, and for resource r. A known access token that has ended is errEnded; any other token is a bare core.ErrInvalidToken. A store failure is returned as itself, so the MCP access check can answer 5xx rather than send the assistant to sign in again.

It reads no person: a term reaches it as the token's expiry, and the MCP access check refuses a person who is not active, as it refuses a disabled one.

It also records the grant's last use, at most once a minute, for the connections list.

Jump to

Keyboard shortcuts

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