middlewares

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken     = errors.New("invalid token")
	ErrTokenExpired     = errors.New("token expired")
	ErrInvalidSignature = errors.New("invalid signing method")
)

Functions

func ClearAuthCookies

func ClearAuthCookies(c *fiber.Ctx)

ClearAuthCookies removes both access and refresh token cookies

func ConfigureLogger

func ConfigureLogger(env string) *slog.Logger

func IsAuthenticated

func IsAuthenticated(config *JWTConfig, require2FA bool, isPage bool) fiber.Handler

func NewCORS

func NewCORS(config CORSConfig) fiber.Handler

NewCORS creates a new CORS middleware with the given config

func RedirectIfAuthenticated

func RedirectIfAuthenticated(config *JWTConfig) fiber.Handler

func SetAuthCookies

func SetAuthCookies(c *fiber.Ctx, accessToken, refreshToken string, config *JWTConfig)

SetAuthCookies sets both access and refresh token cookies

func StructuredLogger

func StructuredLogger() fiber.Handler

StructuredLogger logs a Fiber HTTP request using slog.

Types

type CORSConfig

type CORSConfig struct {
	AllowOrigins string
}

CORSConfig holds the configuration for CORS

type JWTClaims

type JWTClaims struct {
	ID            string `json:"id"`
	AMR           string `json:"amr"`
	Type          string `json:"type"`   // "access" or "refresh"
	Device        string `json:"device"` // "mobile" or "desktop"
	URL           string `json:"url"`    // URL associated with token issuance
	TwoFAEnabled  bool   `json:"twoFA_enabled"`
	TwoFAVerified bool   `json:"twoFA_verified"`
	jwt.RegisteredClaims
}

type JWTConfig

type JWTConfig struct {
	SecretKey            string
	AccessTokenDuration  time.Duration
	RefreshTokenDuration time.Duration
}

func NewJWTConfig

func NewJWTConfig(secretKey string) *JWTConfig

NewJWTConfig creates a new JWT configuration

func (*JWTConfig) DecodeToken

func (config *JWTConfig) DecodeToken(tokenString string) (*JWTClaims, error)

DecodeToken decodes the JWT token and returns the claims

func (*JWTConfig) GenerateTokens

func (config *JWTConfig) GenerateTokens(userID string, otpFaVerified, otpFaEnabled bool, authMethod, device, url string) (accessToken, refreshToken string, err error)

GenerateTokens creates both access and refresh tokens

Jump to

Keyboard shortcuts

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