auth

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKey

func APIKey(config APIKeyConfig) goexpress.Middleware

APIKey returns an API key authentication middleware

func BasicAuth

func BasicAuth(config BasicAuthConfig) goexpress.Middleware

BasicAuth returns a basic authentication middleware

func CheckPassword

func CheckPassword(password, hash string) bool

CheckPassword checks if a password matches the hash

func GenerateToken

func GenerateToken(claims jwt.MapClaims, secret string, expirationTime time.Duration) (string, error)

GenerateToken generates a JWT token with the given claims

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a password using bcrypt

func JWT

func JWT(config JWTConfig) goexpress.Middleware

JWT returns a JWT authentication middleware

func RefreshToken

func RefreshToken(tokenString, secret string, expirationTime time.Duration) (string, error)

RefreshToken generates a new token from an existing one

func SecureCompare

func SecureCompare(a, b string) bool

SecureCompare performs a constant-time comparison of two strings

func Session

func Session(config SessionConfig) goexpress.Middleware

Session returns a session middleware

func VerifyToken

func VerifyToken(tokenString, secret string) (jwt.MapClaims, error)

VerifyToken verifies a JWT token and returns the claims

Types

type APIKeyConfig

type APIKeyConfig struct {
	Validator    func(key string) bool
	KeyLookup    string // "header:<name>" or "query:<name>"
	ContextKey   string
	ErrorHandler goexpress.HandlerFunc
}

APIKeyConfig holds API key authentication configuration

type BasicAuthConfig

type BasicAuthConfig struct {
	Validator    func(username, password string) bool
	Realm        string
	ErrorHandler goexpress.HandlerFunc
}

BasicAuthConfig holds basic authentication configuration

type JWTConfig

type JWTConfig struct {
	Secret         string
	SigningMethod  jwt.SigningMethod
	TokenLookup    string // "header:<name>" or "query:<name>" or "cookie:<name>"
	ContextKey     string
	ErrorHandler   goexpress.HandlerFunc
	SkipperFunc    func(*goexpress.Context) bool
	ExpirationTime time.Duration
}

JWTConfig holds JWT configuration

func DefaultJWTConfig

func DefaultJWTConfig(secret string) JWTConfig

DefaultJWTConfig returns a default JWT configuration

type SessionConfig

type SessionConfig struct {
	Store        SessionStore
	CookieName   string
	CookiePath   string
	CookieDomain string
	MaxAge       int
	Secure       bool
	HttpOnly     bool
	SameSite     http.SameSite
}

SessionConfig holds session configuration

func DefaultSessionConfig

func DefaultSessionConfig(store SessionStore) SessionConfig

DefaultSessionConfig returns a default session configuration

type SessionStore

type SessionStore interface {
	Get(id string) (map[string]interface{}, error)
	Set(id string, data map[string]interface{}) error
	Delete(id string) error
}

SessionStore is an interface for session storage

Jump to

Keyboard shortcuts

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