auth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgon2Hash         = errors.New("argon2 encoded hash is not in the correct format")
	ErrIncompatibleArgon2Version = errors.New("incompatible argon2 version")
)
View Source
var ErrTokenVersionMismatch = errors.New("token version mismatch")

Functions

func CompareArgon2id

func CompareArgon2id(hash, password string) bool

CompareArgon2id returns true if password matches the Argon2id-encoded hash.

func ComparePassword

func ComparePassword(hash, password string) bool

ComparePassword compares a password with a hash.

func GenerateSecret

func GenerateSecret() (string, error)

GenerateSecret creates a 32-byte random secret for signing.

func HashArgon2id

func HashArgon2id(password string) (string, error)

HashArgon2id hashes a password using Argon2id and returns a PHC-encoded string.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a password using bcrypt.

func ParseUnverified

func ParseUnverified(tokenString string, claims *Claims) (*jwt.Token, error)

ParseUnverified parses a JWT without verifying the signature.

func Sign

func Sign(cfg Config, userID uint, username, role string, tokenVersion int, secret string) (string, error)

Sign creates a signed JWT for the user.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UserID       uint   `json:"userId"`
	Username     string `json:"username"`
	Role         string `json:"role"`
	TokenVersion int    `json:"tokenVersion"`
}

Claims holds JWT claims.

func Validate

func Validate(tokenString, secret string, cfg Config) (*Claims, error)

Validate parses and validates a JWT, returning claims if valid.

type Config

type Config struct {
	Issuer     string
	Audience   string
	ExpiryDays int
}

Config holds JWT configuration.

type ContextKey

type ContextKey string

ContextKey is the type for context keys.

const ClaimsKey ContextKey = "claims"

ClaimsKey is the context key for JWT claims.

Jump to

Keyboard shortcuts

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