auth

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: AGPL-3.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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