auth

package
v0.0.0-...-bf86f35 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(authConfig *config.AuthConfig, routeAuth *config.RouteAuth, next http.Handler) http.Handler

Middleware handles authentication and authorization

func SetAuthContext

func SetAuthContext(r *http.Request, authCtx *AuthContext) *http.Request

SetAuthContext stores auth context in request context

func StoreAuthContext

func StoreAuthContext(r *http.Request, authCtx *AuthContext) *http.Request

StoreAuthContext stores auth context in request context

func ValidateAuthorization

func ValidateAuthorization(r *http.Request, routeAuth *config.RouteAuth, authCtx *AuthContext) (bool, error)

ValidateAuthorization performs RBAC and scope validation

func ValidateCertChain

func ValidateCertChain(cert *x509.Certificate, caCert *x509.Certificate) error

ValidateCertChain validates the certificate chain

Types

type AuthContext

type AuthContext struct {
	Authenticated  bool
	IdentityType   string // "user", "device", "service"
	UserID         string
	ClientID       string
	Roles          []string
	Scopes         []string
	CertCommonName string
}

AuthContext holds authentication and authorization information

func ExtractAuthContext

func ExtractAuthContext(r *http.Request) *AuthContext

ExtractAuthContext extracts authentication context from request

func GetAuthContext

func GetAuthContext(r *http.Request) *AuthContext

GetAuthContext retrieves auth context from request context

func ValidateAPIKey

func ValidateAPIKey(r *http.Request, cfg *config.APIKeyConfig) (*AuthContext, error)

ValidateAPIKey validates API key and returns auth context

func ValidateJWT

func ValidateJWT(r *http.Request, cfg *config.JWTConfig) (*AuthContext, error)

ValidateJWT validates JWT token and extracts authentication context

func ValidateMTLS

func ValidateMTLS(r *http.Request, routeAuth *config.RouteAuth) (*AuthContext, error)

ValidateMTLS validates client certificate and extracts identity

type CustomClaims

type CustomClaims struct {
	jwt.RegisteredClaims
	Roles  []string `json:"roles,omitempty"`
	Scopes []string `json:"scopes,omitempty"`
	UserID string   `json:"user_id,omitempty"`
}

CustomClaims extends JWT claims with roles and scopes

Jump to

Keyboard shortcuts

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