Help us shape the future of Go! Take the 2026 Go Developer Survey

oauthserver

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package oauthserver is the OAuth 2.1 authorization server for MCP connectors (ADR 0016, phase 2): discovery documents (RFC 9728, RFC 8414), dynamic client registration (RFC 7591), the PKCE authorization-code flow and the token endpoint. The consent screen is a SPA route; the signed-in user's decision arrives through the site API and is handled by Service.Decide. The token endpoint issues ordinary scoped API tokens, so /mcp and /api authenticate them exactly like a hand-made token.

Index

Constants

View Source
const (

	// ConsentPath is the SPA route that renders the consent screen.
	ConsentPath = "/oauth/consent"
)

Paths served by the Go binary. The consent screen is the SPA route ConsentPath.

Variables

View Source
var (
	// ErrUnknownClient means the client_id was never registered.
	ErrUnknownClient = errors.New("unknown client")
	// ErrInvalidRequest means the authorization request is malformed or does not
	// match the client's registration (the message is safe to show).
	ErrInvalidRequest = errors.New("invalid authorization request")
)

Functions

func ClientHost

func ClientHost(clientID string) string

ClientHost is the host of a metadata client's client_id, shown on the consent screen so the user sees who is asking; empty for a registered client.

func IsMetadataClientID

func IsMetadataClientID(clientID string) bool

IsMetadataClientID reports whether a client_id is a URL (a Client ID Metadata Document) rather than an identifier handed out by dynamic client registration.

func NewFetcher

func NewFetcher(allow webhook.Allowlist) webhook.Doer

NewFetcher is the client that downloads metadata documents: SSRF-hardened, honouring the Instance's internal allowlist (ADR 0039), never following redirects.

func ResourceMetadataURL

func ResourceMetadataURL(mcpOrigin string) string

ResourceMetadataURL is where /mcp points unauthenticated clients (RFC 9728), on the MCP origin.

func ResourceURL

func ResourceURL(mcpOrigin string) string

ResourceURL is the canonical URI of the protected MCP resource, served from the MCP origin (the app origin unless SPHERICON_MCP_URL gives MCP its own host).

func SupportedScopes

func SupportedScopes() []string

SupportedScopes lists every scope the authorization server can issue.

Types

type Decision

type Decision struct {
	ClientID      string
	RedirectURI   string
	State         string
	CodeChallenge string
	Scope         string
	WorkspaceID   int64
	Approve       bool
	AllowSend     bool
}

Decision is the signed-in user's answer to an authorization request. The caller has already verified the user belongs to WorkspaceID.

type Request

type Request struct {
	ClientName string
	// ClientHost is the host of a metadata client's client_id URL, empty for a registered client.
	ClientHost string
	// LocalRedirect is set when the redirect URI is on a loopback host, where any program
	// on the user's machine can be listening.
	LocalRedirect bool
	RedirectURI   string
	// Scopes are granted by default; SendScopes only on explicit opt-in.
	Scopes     []string
	SendScopes []string
}

Request is a validated authorization request, ready for the consent screen.

type Server

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

Server mounts the OAuth protocol endpoints.

func New

func New(svc *Service, appURL, mcpURL string) *Server

New builds the server over the service; appURL is the public origin and the OAuth issuer, and mcpURL the origin of the MCP resource (the same as appURL on a single host).

func (*Server) Mount

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

Mount registers discovery, registration, authorize and token endpoints.

type Service

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

Service holds the authorization server's state operations.

func NewService

func NewService(client *ent.Client, fetcher webhook.Doer) *Service

NewService builds the service over the ent client; fetcher downloads Client ID Metadata Documents and must come from webhook.NewClient or NewClientAllowing.

func (*Service) Decide

func (s *Service) Decide(ctx context.Context, d Decision) (string, error)

Decide records the user's decision and returns the URL to send their browser to: back to the client with a one-time code, or with access_denied.

func (*Service) Describe

func (s *Service) Describe(ctx context.Context, clientID, redirectURI, scope string) (*Request, error)

Describe validates the client and redirect URI of an authorization request and reports what it asks for.

Jump to

Keyboard shortcuts

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