iammiddleware

package
v1.37.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package iammiddleware provides Gin middleware for validating Hanzo IAM (hanzo.id) JWT tokens. It uses the existing auth.IAMClient for JWKS-based token validation and sets IAM claims in the Gin context for downstream handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIAMClaims

func GetIAMClaims(c *gin.Context) *auth.IAMClaims

GetIAMClaims returns the IAM claims from context, or nil if not IAM-authenticated.

func GetIAMTier added in v1.36.4

func GetIAMTier(c *gin.Context) string

GetIAMTier returns the user's billing tier from context. Returns an empty string if the request is not IAM-authenticated or no tier is set.

func IAMTokenRequired

func IAMTokenRequired() gin.HandlerFunc

IAMTokenRequired validates hanzo.id JWT tokens via JWKS. If a valid IAM token is found, it resolves the org from the token's "owner" claim and sets both IAM context keys and the standard "organization" + "permissions" keys that downstream handlers expect.

Auth guard behavior:

  • IAM enabled but client initialization failed: 503 Service Unavailable
  • Bearer token present but invalid: 401 Unauthorized (no fallthrough)
  • No Bearer token present: fall through to legacy org-token auth

func Init

func Init(cfg *auth.IAMConfig) error

Init initializes the IAM middleware with the given configuration. Must be called before IAMTokenRequired() middleware is used. Safe to call multiple times; last call wins.

func InitKV added in v1.36.4

func InitKV(kv KVCache)

InitKV wires a KV client for caching IAM org lookups. Call from app.Bootstrap() after infra is connected. Passing nil is safe and disables KV caching.

func IsIAMAuthenticated

func IsIAMAuthenticated(c *gin.Context) bool

IsIAMAuthenticated checks whether the current request was authenticated via IAM.

Types

type KVCache added in v1.36.4

type KVCache interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value string, ttl time.Duration) error
	Delete(ctx context.Context, keys ...string) error
}

KVCache is the minimal interface required for org-lookup caching. *infra.KVClient satisfies this interface.

Jump to

Keyboard shortcuts

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