auth

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextUsernameKey        contextKey = "username"
	ContextJWTTokenKey        contextKey = "jwt_token"
	ContextJWTIssuerConfigKey contextKey = "jwt_issuer_config"
)

Variables

This section is empty.

Functions

func CallerIdentityFromRequest added in v0.3.0

func CallerIdentityFromRequest(ctx context.Context, r *http.Request) (string, error)

CallerIdentityFromRequest resolves the caller identity. Priority: identity header (per-issuer, if configured and present) > JWT claim from matched issuer config. The issuer config is set in context by JWTHandler when a token is validated.

func GetIdentityFromContext added in v0.3.0

func GetIdentityFromContext(ctx context.Context, identityClaim string) (string, error)

GetIdentityFromContext returns the configured JWT claim value used as the request identity.

func GetJWTIssuerConfigFromContext added in v0.3.1

func GetJWTIssuerConfigFromContext(ctx context.Context) (config.JWTIssuerConfig, bool)

func GetJWTTokenFromContext added in v0.3.0

func GetJWTTokenFromContext(ctx context.Context) *jwt.Token

func GetUsernameFromContext

func GetUsernameFromContext(ctx context.Context) string

func SetJWTIssuerConfigContext added in v0.3.1

func SetJWTIssuerConfigContext(ctx context.Context, cfg config.JWTIssuerConfig) context.Context

func SetJWTTokenContext added in v0.3.0

func SetJWTTokenContext(ctx context.Context, token *jwt.Token) context.Context

func SetUsernameContext

func SetUsernameContext(ctx context.Context, username string) context.Context

Types

type CallerIdentityMiddleware added in v0.3.0

type CallerIdentityMiddleware interface {
	ResolveCallerIdentity(next http.Handler) http.Handler
}

CallerIdentityMiddleware resolves and attaches the caller identity used for audit fields.

func NewCallerIdentityMiddleware added in v0.3.0

func NewCallerIdentityMiddleware() CallerIdentityMiddleware

type JWTHandler added in v0.3.0

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

JWTHandler validates JWT tokens on incoming requests. Call Close() during shutdown to stop the background JWKS refresh goroutine.

func NewJWTHandler added in v0.3.0

func NewJWTHandler(ctx context.Context, cfg JWTHandlerConfig) (*JWTHandler, error)

func (*JWTHandler) Close added in v0.3.0

func (h *JWTHandler) Close()

func (*JWTHandler) Middleware added in v0.3.1

func (h *JWTHandler) Middleware(next http.Handler) http.Handler

Middleware returns a standard HTTP middleware that validates JWT tokens. Requests with a valid token proceed to next with claims in context; requests without valid credentials receive a 401 response.

type JWTHandlerConfig added in v0.3.0

type JWTHandlerConfig struct {
	Issuers []config.JWTIssuerConfig
}

type Payload

type Payload struct {
	Username  string `json:"username"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Issuer    string `json:"iss"`
	ClientID  string `json:"clientId"`
}

Payload defines the structure of the JWT payload we expect

func GetAuthPayloadFromContext

func GetAuthPayloadFromContext(ctx context.Context) (*Payload, error)

Jump to

Keyboard shortcuts

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