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

auth

package
v0.1.58 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bearer

func Bearer(ctx context.Context) string

func CanonicalUserID added in v0.1.29

func CanonicalUserID(ctx context.Context) string

func EffectiveUserID

func EffectiveUserID(ctx context.Context) string

func EnsureUser

func EnsureUser(ctx context.Context, cfg *Config) context.Context

EnsureUser populates a user identity in context when missing using config fallbacks (e.g., local mode default username). Returns the original context when no action is needed.

func IDToken

func IDToken(ctx context.Context) string

func MCPAuthToken

func MCPAuthToken(ctx context.Context, useIDToken bool) string

func Provider added in v0.1.5

func Provider(ctx context.Context) string

func TokensFromContext

func TokensFromContext(ctx context.Context) *scyauth.Token

func WithBearer

func WithBearer(ctx context.Context, value string) context.Context

func WithCanonicalUserID added in v0.1.29

func WithCanonicalUserID(ctx context.Context, value string) context.Context

func WithIDToken

func WithIDToken(ctx context.Context, value string) context.Context

func WithProvider added in v0.1.5

func WithProvider(ctx context.Context, value string) context.Context

func WithTokens

func WithTokens(ctx context.Context, value *scyauth.Token) context.Context

func WithUserInfo

func WithUserInfo(ctx context.Context, value *UserInfo) context.Context

func WithoutTokens added in v0.1.22

func WithoutTokens(ctx context.Context) context.Context

Types

type Config

type Config struct {
	Enabled         bool     `yaml:"enabled" json:"enabled"`
	CookieName      string   `yaml:"cookieName" json:"cookieName"`
	SessionTTLHours int      `yaml:"sessionTTLHours,omitempty" json:"sessionTTLHours,omitempty"` // cookie/session lifetime; default 168h (7 days)
	DefaultUsername string   `yaml:"defaultUsername" json:"defaultUsername"`
	IpHashKey       string   `yaml:"ipHashKey" json:"ipHashKey"`
	TrustedProxies  []string `yaml:"trustedProxies" json:"trustedProxies"`
	RedirectPath    string   `yaml:"redirectPath" json:"redirectPath"`
	// New unified model
	OAuth *OAuth `yaml:"oauth" json:"oauth"`
	Local *Local `yaml:"local" json:"local"`
	JWT   *JWT   `yaml:"jwt" json:"jwt,omitempty"`
}

Config defines global authentication settings. Modes:

  • local : username-only with HttpOnly session cookie
  • bff : backend-for-frontend OAuth (PKCE) setting HttpOnly cookie
  • oidc : frontend obtains tokens and calls APIs with Bearer; server validates
  • mixed : accept both Bearer and cookie
  • jwt : private/public key JWT — server signs tokens and verifies with RSA/HMAC

func (*Config) IsBearerAccepted

func (c *Config) IsBearerAccepted() bool

IsBearerAccepted returns true when a Bearer token is an acceptable auth credential given the current configuration.

func (*Config) IsCookieAccepted

func (c *Config) IsCookieAccepted() bool

IsCookieAccepted returns true when a session cookie is an acceptable auth credential given the current configuration.

func (*Config) IsJWTAuth

func (c *Config) IsJWTAuth() bool

IsJWTAuth returns true when auth is enabled and JWT (private/public key) mode is the active auth mechanism.

func (*Config) IsLocalAuth

func (c *Config) IsLocalAuth() bool

IsLocalAuth returns true when auth is enabled and the effective mode is local-only (i.e. cookie-based session, no OAuth mode configured).

func (*Config) Validate

func (c *Config) Validate() error

Validate checks internal consistency; when disabled minimal fields are required.

type JWT

type JWT struct {
	Enabled bool `yaml:"enabled" json:"enabled"`
	// RSA holds one or more scy resource URLs pointing to RSA public keys (PEM).
	// Example: "/path/to/public.pem" or "scy://secret/public_key|blowfish://default"
	RSA []string `yaml:"rsa,omitempty" json:"rsa,omitempty"`
	// HMAC is a scy resource URL pointing to the HMAC shared secret.
	HMAC string `yaml:"hmac,omitempty" json:"hmac,omitempty"`
	// CertURL is a JWKS endpoint URL for key discovery (alternative to RSA/HMAC).
	CertURL string `yaml:"certURL,omitempty" json:"certURL,omitempty"`
	// RSAPrivateKey is a scy resource URL pointing to the RSA private key for signing.
	// Only needed when the server itself signs tokens (e.g. for local JWT issuance).
	RSAPrivateKey string `yaml:"rsaPrivateKey,omitempty" json:"rsaPrivateKey,omitempty"`
}

JWT configures private/public key JWT authentication. When enabled, Bearer tokens are cryptographically verified using the configured RSA public keys or HMAC secret (via scy/auth/jwt/verifier).

type Local

type Local struct {
	Enabled bool `yaml:"enabled" json:"enabled"`
}

type OAuth

type OAuth struct {
	Mode   string       `yaml:"mode" json:"mode"` // bearer|spa|bff|mixed
	Name   string       `yaml:"name" json:"name"`
	Label  string       `yaml:"label" json:"label"`
	Client *OAuthClient `yaml:"client" json:"client"`
}

New unified structures

type OAuthClient

type OAuthClient struct {
	ConfigURL      string   `yaml:"configURL" json:"configURL"`       // for bff
	DiscoveryURL   string   `yaml:"discoveryURL" json:"discoveryURL"` // for spa/bearer
	JWKSURL        string   `yaml:"jwksURL" json:"jwksURL"`           // for bearer verifier
	RedirectURI    string   `yaml:"redirectURI" json:"redirectURI"`
	ClientID       string   `yaml:"clientID" json:"clientID"`
	Scopes         []string `yaml:"scopes" json:"scopes"`
	WebUIScopes    []string `yaml:"webUIScopes,omitempty" json:"webUIScopes,omitempty"`
	MobileUIScopes []string `yaml:"mobileUIScopes,omitempty" json:"mobileUIScopes,omitempty"`
	CLIScopes      []string `yaml:"cliScopes,omitempty" json:"cliScopes,omitempty"`
	Issuer         string   `yaml:"issuer" json:"issuer"`       // optional expected iss claim
	Audiences      []string `yaml:"audiences" json:"audiences"` // optional expected aud claim(s)
}

type UserInfo

type UserInfo = shared.UserInfo

UserInfo is transport partitioning metadata; authoritative application facts continue to come from Core's configured identity and authorization providers.

func User

func User(ctx context.Context) *UserInfo

Directories

Path Synopsis
Package mcpauth defines the stable Agently-typed error surface for delegated MCP OAuth.
Package mcpauth defines the stable Agently-typed error surface for delegated MCP OAuth.

Jump to

Keyboard shortcuts

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