auth

package
v0.0.124 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: GPL-3.0 Imports: 11 Imported by: 0 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWTManager

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

JWTManager handles creation and validation of JWT access tokens and refresh tokens.

func NewJWTManager

func NewJWTManager(secret string, accessTTL, refreshTTL time.Duration) *JWTManager

NewJWTManager creates a JWTManager with the given signing secret and TTLs.

func (*JWTManager) GenerateAccessToken

func (m *JWTManager) GenerateAccessToken(user *model.User) (string, error)

GenerateAccessToken creates a signed JWT containing the user's claims.

func (*JWTManager) GenerateRefreshToken

func (m *JWTManager) GenerateRefreshToken() (raw string, hash string, err error)

GenerateRefreshToken produces a cryptographically random refresh token. It returns the raw base64url-encoded value (to send to the client) and the SHA-256 hash of that value (to store server-side).

func (*JWTManager) GenerateRunToken added in v0.0.72

func (m *JWTManager) GenerateRunToken(runID, invokerID, agentID string, expiresAt time.Time) (string, error)

GenerateRunToken mints the per-run token the local MCP server uses for tool calls. UserID is the INVOKER (permissions), ActorID the agent instance (authorship), and it expires with the run's deadline.

func (*JWTManager) GenerateRunnerToken added in v0.0.72

func (m *JWTManager) GenerateRunnerToken(user *model.User, tokenID string, expiresAt time.Time) (string, error)

GenerateRunnerToken mints the long-lived token an ex-runner authenticates with. tokenID becomes the `jti`: it names the RunnerToken row the runner middleware requires to exist, which is what makes one install revocable on its own. Accepted only by the runner middleware.

func (*JWTManager) RefreshTTL

func (m *JWTManager) RefreshTTL() time.Duration

RefreshTTL returns the configured refresh token TTL.

func (*JWTManager) ValidateToken

func (m *JWTManager) ValidateToken(tokenStr string) (*model.TokenClaims, error)

ValidateToken parses and validates a JWT string, returning the embedded claims.

type OIDCProvider

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

OIDCProvider wraps an OpenID Connect provider for authentication.

func NewOIDCProvider

func NewOIDCProvider(ctx context.Context, issuer, clientID, clientSecret, redirectURL string, extraScopes ...string) (*OIDCProvider, error)

NewOIDCProvider discovers the OIDC provider and configures OAuth2. extraScopes are requested on top of openid/profile/email, e.g. offline_access plus an API scope when the app acts as the user later.

func (*OIDCProvider) AuthURL

func (p *OIDCProvider) AuthURL(state, nonce string) string

AuthURL returns the URL to redirect the user to for authentication. The nonce is bound into the request so the ID token returned on callback can be checked against it, preventing ID-token replay/injection.

func (*OIDCProvider) Exchange

func (p *OIDCProvider) Exchange(ctx context.Context, code, nonce string) (*OIDCUserInfo, error)

Exchange trades an authorization code for tokens, verifies the ID token (including that its nonce matches the one bound at AuthURL time), and extracts user profile information.

func (*OIDCProvider) OAuth2Config added in v0.0.116

func (p *OIDCProvider) OAuth2Config() *oauth2.Config

OAuth2Config is the provider's OAuth2 client, for renewing a user's token with the refresh token their login returned.

type OIDCUserInfo

type OIDCUserInfo struct {
	Email   string
	Name    string
	Picture string
	// ObjectID is the Azure AD directory object id (`oid` claim). Empty for
	// identity providers that don't emit it; when present it keys Microsoft
	// Graph lookups without assuming email == userPrincipalName.
	ObjectID string
	// Issuer + Subject (`iss` + `sub`) identify the user at the provider —
	// unlike the email claim, they don't change when an address does.
	Issuer  string
	Subject string
	// EmailVerified is the `email_verified` claim, nil when the provider
	// omits it (Entra ID does).
	EmailVerified *bool
	// Token is the provider's token response. With extra scopes requested
	// (NewOIDCProvider) its access and refresh tokens act as the user on the
	// API those scopes name.
	Token *oauth2.Token
}

OIDCUserInfo holds user profile data returned by the identity provider.

Jump to

Keyboard shortcuts

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