auth

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyJwtClaims = errors.New("empty jwt claims found in context")
View Source
var ErrNoJwtClaims = errors.New("no jwt claims found in context")

Functions

func GenerateJWT

func GenerateJWT(username, email string, uuid uuid.UUID, jwtKey []byte, validFor time.Duration) (string, error)

func GetUserUuidFromCtx

func GetUserUuidFromCtx(ctx context.Context) (uuid.UUID, error)

func HttpAllowOnlyAdmins

func HttpAllowOnlyAdmins(adminAPIKey []byte) func(http.Handler) http.Handler

HttpAllowOnlyAdmins allows requests authenticated either by an admin JWT or by the server-to-server admin API key.

func HttpJwtAuthentication

func HttpJwtAuthentication(jwtKey []byte, opts ...JwtAuthOption) func(next http.Handler) http.Handler

HttpJwtAuthentication validates JWT token and adds the claims to the request context. Pass WithSecureCookie and optionally WithPasswordChangedAtLookup.

func IsAdmin

func IsAdmin(ctx context.Context) bool

Types

type ClaimsKeyType

type ClaimsKeyType string
var CtxJwtClaimsKey ClaimsKeyType = "jwtClaims"

type JwtAuthOption added in v1.1.1

type JwtAuthOption func(*jwtAuthConfig)

func WithPasswordChangedAtLookup added in v1.1.1

func WithPasswordChangedAtLookup(lookup PasswordChangedAtLookup) JwtAuthOption

func WithSecureCookie added in v1.1.1

func WithSecureCookie(secure bool) JwtAuthOption

type JwtClaims

type JwtClaims struct {
	Username string   `json:"username,omitempty"`
	UUID     string   `json:"uuid,omitempty"`
	Scopes   []string `json:"scopes,omitempty"`
	jwt.RegisteredClaims
}

func ValidateJWT

func ValidateJWT(tokenStr string, jwtKey []byte) (*JwtClaims, error)

type PasswordChangedAtLookup added in v1.1.1

type PasswordChangedAtLookup func(ctx context.Context, userUUID uuid.UUID) (time.Time, error)

PasswordChangedAtLookup returns when the user's password was last changed.

Jump to

Keyboard shortcuts

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