middleware

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataUserEmail = "x-aibrix-user-email"
	MetadataUserID    = "x-aibrix-user-id"
)

gRPC metadata keys used by the gateway to propagate the caller identity from the HTTP request context to gRPC handlers (which receive a fresh context across the gateway dial).

View Source
const IDTokenContextKey contextKey = "id_token"

IDTokenContextKey is the context key for storing the raw OIDC ID token associated with the current session, when available. Consumers (e.g. the SSO single-logout handler) can retrieve it via GetIDToken.

View Source
const UserContextKey contextKey = "user"

UserContextKey is the context key for storing UserInfo.

Variables

This section is empty.

Functions

func GetIDToken

func GetIDToken(ctx context.Context) string

GetIDToken returns the raw OIDC ID token attached to the request context, or the empty string if there is none (basic / dev modes, or no session).

Types

type AuthConfig

type AuthConfig struct {
	Mode                      string // "dev", "oidc", "basic"
	OIDCIssuerURL             string
	OIDCClientID              string
	OIDCClientSecret          string
	OIDCRedirectURL           string
	OIDCPostLogoutRedirectURL string
	OIDCEndSessionURL         string
	OIDCGroupsClaim           string
	OIDCAdminGroups           string
	OIDCAdminEmails           string
	OIDCSigningAlg            string
	SessionSecret             string
	DevUserName               string
	DevUserEmail              string
	BasicUsername             string
	BasicPassword             string
}

AuthConfig holds authentication configuration.

type AuthMiddleware

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

AuthMiddleware provides authentication for HTTP handlers.

func NewAuthMiddleware

func NewAuthMiddleware(cfg AuthConfig) (*AuthMiddleware, error)

NewAuthMiddleware creates a new AuthMiddleware with the given configuration. SessionSecret must be non-empty; callers should obtain it from config.Load, which enforces a strong secret in non-dev modes. In OIDC mode, this performs provider discovery against OIDCIssuerURL and returns an error if discovery fails.

func (*AuthMiddleware) Handler

func (a *AuthMiddleware) Handler(next http.Handler) http.Handler

Handler wraps an http.Handler with authentication.

func (*AuthMiddleware) RegisterAuthRoutes

func (a *AuthMiddleware) RegisterAuthRoutes(mux *runtime.ServeMux)

RegisterAuthRoutes registers authentication endpoints on the grpc-gateway mux.

Routes registered:

GET  /api/v1/auth/config   -> returns auth mode info (public)
GET  /api/v1/auth/login    -> redirect to OIDC provider (oidc mode)
POST /api/v1/auth/login    -> basic auth login (basic mode)
GET  /api/v1/auth/callback -> OIDC callback handler (oidc mode)
GET  /api/v1/auth/userinfo -> current user info (all modes)
POST /api/v1/auth/logout   -> clear session (all modes)

type UserInfo

type UserInfo struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Email    string `json:"email"`
	Role     string `json:"role"`
	Username string `json:"username"`
	Picture  string `json:"picture"`
}

UserInfo represents an authenticated user.

func GetUser

func GetUser(ctx context.Context) *UserInfo

GetUser extracts UserInfo from the request context.

Jump to

Keyboard shortcuts

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