Documentation
¶
Overview ¶
Package apptoken is the platform's token for an app's backend (docs/build-apps/10-auth.md): a short JWT the host puts in the calls to an app's MCP server so the server knows who calls, for which app, without a sign-in of its own. The hub signs it with one Ed25519 key of the deployment and publishes the public half at /.well-known/jwks.json; a machine without a hub signs with its own key. A backend checks the signature, the issuer, its own audience and the expiry.
Nothing here holds a person's password or an identity provider's token: the token says who the hub signed in, and lives minutes.
Index ¶
Constants ¶
const ( TTL = 5 * time.Minute MaxTTL = 10 * time.Minute // Type is the JWT's typ header: a backend may insist on it, so an ID token of the same issuer is never taken for it. Type = "harnessly-app+jwt" // JWKSPath is where a hub (and a machine without one) publishes its public keys. JWKSPath = "/.well-known/jwks.json" // DiscoveryPath is the OpenID discovery document of the issuer: its iss and where its keys are, so a backend checks // the tokens with a stock OIDC library. DiscoveryPath = "/.well-known/openid-configuration" )
TTL is how long a token lives; MaxTTL bounds what a caller may ask.
const ( GrantTokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange" TokenTypeJWT = "urn:ietf:params:oauth:token-type:jwt" TokenTypeAccess = "urn:ietf:params:oauth:token-type:access_token" )
The grant and token types of RFC 8693.
Variables ¶
var ( ErrNoAudience = errors.New("apptoken: a token needs an audience") ErrNoSubject = errors.New("apptoken: a token needs a subject") ErrInvalid = errors.New("apptoken: the token is not valid") )
Errors of Mint and Verify.
var ( ErrExchangeDenied = errors.New("apptoken: the identity provider refused the exchange") ErrIdPUnreachable = errors.New("apptoken: the identity provider did not answer") ErrExchangeMisconfig = errors.New("apptoken: the token exchange is not set up") )
Errors of Exchange: the provider refused (no new sign-in on our side mends it), or did not answer.
Functions ¶
func KeyID ¶
KeyID is the key's id in the JWKS: the base64url SHA-256 of the public key, cut to 16 characters. The same key has the same id on every replica of a hub.
func LoadOrCreateKey ¶
func LoadOrCreateKey(path string) (ed25519.PrivateKey, error)
LoadOrCreateKey reads an Ed25519 private key (PKCS#8 PEM) from path, or makes one and writes it there (0600) when the file does not exist. Every replica of a hub must read the same file.
Types ¶
type Claims ¶
type Claims struct {
Issuer string `json:"iss"`
Subject string `json:"sub"`
Audience string `json:"aud"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
Org string `json:"org,omitempty"`
Space string `json:"space,omitempty"`
App string `json:"app"`
Server string `json:"server,omitempty"`
Machine string `json:"machine,omitempty"`
IssuedAt time.Time `json:"-"`
Expiry time.Time `json:"-"`
ID string `json:"-"`
}
Claims are what the token says. Subject is the person's stable id at the issuer; Email and Name are for display and logs, not for access decisions unless the backend trusts the issuer's emails. Org and Space are the person's organization and team on the hub (empty on a machine without one). App and Server name the app and its MCP server the call is for; Audience is the backend the token is good for, and nothing else.
type ExchangeConfig ¶
type ExchangeConfig struct {
TokenURL string
ClientID string
ClientSecret string
// SubjectTokenType is how the provider is told what the subject token is; TokenTypeJWT when empty.
SubjectTokenType string
}
ExchangeConfig is the hub's client at the corporate provider.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer mints the tokens of one issuer. The first key signs; the others are still published so the tokens they signed before a rotation keep verifying until they expire.
func NewSigner ¶
func NewSigner(issuer string, key ed25519.PrivateKey, previous ...ed25519.PublicKey) (*Signer, error)
NewSigner is a signer for issuer with key; previous are public keys of earlier rotations, published but not used.