auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: AGPL-3.0 Imports: 9 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, cookieSecure ...bool) func(next http.Handler) http.Handler

HttpJwtAuthentication validates JWT token and adds the claims to the request context. Optional cookieSecure parameter controls the Secure flag when clearing invalid tokens.

func IsAdmin

func IsAdmin(ctx context.Context) bool

Types

type ClaimsKeyType

type ClaimsKeyType string
var CtxJwtClaimsKey ClaimsKeyType = "jwtClaims"

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)

Jump to

Keyboard shortcuts

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