auth

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessTokenDuration  = 15 * time.Minute
	RefreshTokenDuration = 7 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func AgentIDFromContext

func AgentIDFromContext(ctx interface{ Value(any) any }) uuid.UUID

AgentIDFromContext returns the agent UUID from context, set by AgentMiddleware.

func AgentMiddleware

func AgentMiddleware(jwtSecret string) func(http.Handler) http.Handler

AgentMiddleware validates the agent JWT Bearer token and injects AgentClaims into context.

func CheckPassword

func CheckPassword(hash, password string) error

CheckPassword compares a plaintext password with a bcrypt hash. Returns nil on success, error on mismatch.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a plaintext password using bcrypt.

func IssueAgentToken

func IssueAgentToken(secret string, agentID uuid.UUID) (string, error)

IssueAgentToken creates a signed JWT for an agent container (100-year expiry).

func IssueRefreshToken

func IssueRefreshToken(secret string, userID uuid.UUID, email, tenantRole string) (string, error)

IssueRefreshToken creates a signed refresh token (7 days).

func IssueToken

func IssueToken(secret string, userID uuid.UUID, email, tenantRole string) (string, error)

IssueToken creates a signed access token (15 min).

func IssueTokenWithDuration

func IssueTokenWithDuration(secret string, userID uuid.UUID, email, tenantRole string, duration time.Duration) (string, error)

IssueTokenWithDuration creates a signed token with a custom duration.

func Middleware

func Middleware(jwtSecret string) func(http.Handler) http.Handler

Middleware validates the JWT Bearer token and injects claims into context. It returns 401 for missing, invalid, or expired tokens.

func RequireTenantRole

func RequireTenantRole(minRole string) func(http.Handler) http.Handler

RequireTenantRole returns middleware that checks the user has at least the given role. Uses hierarchy: admin > manager > user. Returns 403 if not authorized.

func RoleAtLeast

func RoleAtLeast(userRole, minRole string) bool

RoleAtLeast returns true if the user's role is >= the minimum required role.

func UserIDFromContext

func UserIDFromContext(ctx context.Context) uuid.UUID

UserIDFromContext returns the user ID from the JWT claims.

Types

type AgentClaims

type AgentClaims struct {
	jwt.RegisteredClaims
	AgentID string `json:"agent_id"`
}

AgentClaims are the JWT claims for agent tokens.

func ValidateAgentToken

func ValidateAgentToken(secret, tokenString string) (*AgentClaims, error)

ValidateAgentToken validates a JWT and returns the agent claims. Rejects tokens that do not have an AgentID claim.

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Email      string `json:"email"`
	TenantRole string `json:"tenant_role"`
}

Claims are the JWT claims for Airlock tokens.

func ClaimsFromContext

func ClaimsFromContext(ctx context.Context) *Claims

ClaimsFromContext retrieves the JWT claims from the context.

func ValidateToken

func ValidateToken(secret, tokenString string) (*Claims, error)

ValidateToken validates a JWT and returns the claims.

Directories

Path Synopsis
Package lockout implements per-(email, ip) login throttling for the airlock auth path.
Package lockout implements per-(email, ip) login throttling for the airlock auth path.

Jump to

Keyboard shortcuts

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