aauthrs

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package aauthrs authenticates AI agents at a resource server with AAuth (draft-hardt-oauth-aauth-protocol), producing a requestprincipal.RequestPrincipal.

An AAuth request carries an HTTP message signature (RFC 9421) and, in the Signature-Key header, the token binding the signing key: an agent token (the agent's identity), a person token (the person the agent acts for, from the person's Person Server), or an auth token (an authorization for this resource, from a Person Server or Access Server). The Authenticator verifies the signature and the token and, depending on the access mode, either accepts the request or answers with the AAuth-Requirement challenge for the next token:

no Signature-Key           → next authenticator (or requirement=agent-token)
agent token                → requirement=person-token
person token               → requirement=auth-token with a resource token
auth token, scopes granted → principal (Type agent)
auth token, scope missing  → requirement=auth-token (step-up)

Person and auth tokens are accepted only from Config.TrustedIssuers, whose keys are discovered through their AAuth metadata and JWKS (cached per the draft). An agent's aauth.Transport follows the challenges automatically.

This package is the only part of SystemForge that imports github.com/aauth-dev/aauth-go.

Index

Constants

View Source
const DefaultJWKSPath = "/.well-known/aauth-resource-jwks.json"

DefaultJWKSPath is where Register serves the resource's JWKS.

Variables

This section is empty.

Functions

func PrincipalID

func PrincipalID(ps, sub string) string

PrincipalID is the PrincipalID this package assigns to the person an agent acts for: the person's Person Server and its subject identifier for this resource, "<ps>#<sub>". A Person Server's sub is directed (it differs per resource) and unique within that server only.

Types

type Authenticator

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

Authenticator verifies AAuth requests. It implements requestprincipal.Authenticator and requestprincipal.Challenger.

func New

func New(cfg Config) (*Authenticator, error)

New validates cfg and returns an Authenticator.

func (*Authenticator) Authenticate

Authenticate implements requestprincipal.Authenticator. A request with no Signature-Key header is left to the next authenticator.

func (*Authenticator) Challenge

func (a *Authenticator) Challenge(h http.Header)

Challenge implements requestprincipal.Challenger: requirement=agent-token (draft §6.1) and a Link to the resource metadata (§11.2.5).

func (*Authenticator) JWKS

func (a *Authenticator) JWKS() aauth.JWKS

JWKS returns the key set holding the resource token signing key (empty when the resource issues none).

func (*Authenticator) JWKSHandler

func (a *Authenticator) JWKSHandler() http.Handler

JWKSHandler serves JWKS as JSON.

func (*Authenticator) Metadata

func (a *Authenticator) Metadata() aauth.ResourceMetadata

Metadata returns the resource's aauth-resource.json document (draft §11.2.4): issuer, jwks_uri (when it issues resource tokens), the access mode, scope descriptions, and the signature requirements.

func (*Authenticator) MetadataHandler

func (a *Authenticator) MetadataHandler() http.Handler

MetadataHandler serves Metadata as JSON.

func (*Authenticator) Register

func (a *Authenticator) Register(mux *http.ServeMux)

Register mounts the metadata document at /.well-known/aauth-resource.json and the JWKS at Config.JWKSPath. Agents and Person Servers discover the resource's key there to verify resource tokens. Mount them outside the authentication middleware.

type Config

type Config struct {
	// Resource is this resource server's identifier (https, host only,
	// e.g. "https://api.example.com"): the aud of the person and auth
	// tokens it accepts and the iss of the resource tokens it issues.
	// Required.
	Resource string

	// TrustedIssuers are the Person Servers and Access Servers whose
	// person and auth tokens this resource accepts. Tokens from any other
	// issuer are refused before any key discovery. Required.
	TrustedIssuers []string

	// AccessMode is the credential the resource requires
	// (aauth.AccessMode*): AccessModeAuthToken (the default) serves only
	// auth tokens; AccessModePersonToken also serves person tokens when
	// the route requires no scopes; AccessModeAgentToken also serves bare
	// agent tokens when the route requires no scopes.
	AccessMode string

	// Scopes returns the scopes a request requires. An auth token must
	// grant all of them; a resource token requests them. Nil requires
	// none.
	Scopes func(r *http.Request) []string

	// Key signs resource tokens, and KeyID is its kid (default: the RFC
	// 7638 thumbprint). Required unless AccessMode is
	// AccessModeAgentToken.
	Key   crypto.Signer
	KeyID string

	// Audience, for four-party access, is the resource's Access Server:
	// resource tokens are addressed to it. Empty means three-party: the
	// Person Server named by the presented token.
	Audience string

	// Resolver locates person and auth token issuer keys. Default: a
	// JWKS resolver (aauth.JWKSResolver) over HTTPClient and JWKSCache.
	// It is always restricted to TrustedIssuers.
	Resolver aauth.KeyResolver
	// AgentResolver locates agent token keys (AccessModeAgentToken).
	// Default: a JWKS resolver over HTTPClient and JWKSCache.
	AgentResolver aauth.KeyResolver
	// HTTPClient performs key discovery. Default: aauth.DiscoveryClient,
	// which reaches only public https destinations; a client supplied here
	// should apply the same egress admission. Local development needs a
	// client that can reach the local issuer.
	HTTPClient *http.Client
	// JWKSCache caches discovered key sets. Default: a new cache.
	JWKSCache *aauth.JWKSCache

	// Signature tunes HTTP message signature verification: the validity
	// window, the clock, and components agents must cover beyond the base
	// set. The zero value uses the library defaults.
	Signature aauth.RequestVerifyOptions

	// CheckSubject is the resource's record check for a person (draft
	// §9.4.3.2): it confirms or establishes the resource's record for
	// (iss, sub). Its error rejects the request.
	CheckSubject func(ctx context.Context, iss, sub string) error

	// Resolve, when set, runs on every accepted request: it may map the
	// principal to an application principal (setting PrincipalID or
	// Organization) or reject the request. Its error is returned from
	// Authenticate unchanged: a *requestprincipal.Error is that response,
	// any other error a 500.
	Resolve func(ctx context.Context, p *requestprincipal.RequestPrincipal) error

	// Limiter, when set, rate-limits resource token issuance per agent
	// key (key "aauth-rs:resource-token:<thumbprint>"); a refusal is a
	// 429 with Retry-After.
	Limiter aauth.Limiter

	// Metadata supplies the display members (name, description, logos,
	// ...) of aauth-resource.json; issuer and jwks_uri are filled in.
	Metadata aauth.ServerMetadata
	// ScopeDescriptions are published in aauth-resource.json for consent
	// screens.
	ScopeDescriptions map[string]string
	// JWKSPath is the path of the resource's JWKS (default
	// DefaultJWKSPath).
	JWKSPath string

	// InsecureSkipIdentifierCheck accepts http and port-bearing
	// identifiers, for development and tests. Never set it in production.
	InsecureSkipIdentifierCheck bool
}

Config configures an Authenticator.

Jump to

Keyboard shortcuts

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