auth

package
v0.10.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserIDOrZero

func GetUserIDOrZero(ctx context.Context) uuid.UUID

GetUserIDOrZero retrieves user ID from context, returns zero value if not found Used for optional auth scenarios on public endpoints.

func MustGetUserID

func MustGetUserID(ctx context.Context) uuid.UUID

MustGetUserID retrieves the authenticated user ID from context For protected endpoints, user_id must exist, otherwise panic This is the recommended approach since auth interceptor guarantees user_id existence

func SetUserID

func SetUserID(ctx context.Context, userID uuid.UUID) context.Context

SetUserID stores the authenticated user ID in context

Types

type AuthInterceptor

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

AuthInterceptor provides JWT authentication for Connect RPC endpoints

func NewAuthInterceptor

func NewAuthInterceptor(validator *JWTValidator, publicProcedures []string) *AuthInterceptor

NewAuthInterceptor creates a new auth interceptor publicProcedures should contain procedure names that don't require authentication

func (*AuthInterceptor) WrapUnary

func (i *AuthInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc

WrapUnary returns a Connect RPC unary interceptor function

type Claims

type Claims struct {
	Sub   string `json:"sub"`   // User ID (UUID format from Supabase)
	Email string `json:"email"` // Optional email
	jwt.RegisteredClaims
}

Claims represents the JWT claims from Supabase auth tokens

func (*Claims) UserID

func (c *Claims) UserID() (uuid.UUID, error)

UserID extracts and parses the UUID from the sub claim

type JWTValidator

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

JWTValidator validates JWT tokens using JWKS from Supabase

func NewJWTValidator

func NewJWTValidator(ctx context.Context, cfg *JWTValidatorConfig) (*JWTValidator, error)

NewJWTValidator creates a new JWT validator with JWKS auto-refresh

func (*JWTValidator) Close

func (v *JWTValidator) Close() error

Close stops the JWKS background refresh and cleans up resources

func (*JWTValidator) ValidateToken

func (v *JWTValidator) ValidateToken(ctx context.Context, tokenString string) (*Claims, error)

ValidateToken validates a JWT token and returns the claims

type JWTValidatorConfig

type JWTValidatorConfig struct {
	JWKSURL       string        // JWKS endpoint URL
	RefreshPeriod time.Duration // How often to refresh JWKS (default: 1 hour)
}

JWTValidatorConfig holds configuration for JWT validation

Jump to

Keyboard shortcuts

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