auth

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey   = fmt.Errorf("user token key is invalid")
	ErrInvalidToken = fmt.Errorf("user token is invalid")
)

Functions

func ContextWithClaims

func ContextWithClaims(ctx context.Context, claims *Claims, token string) context.Context

ContextWithClaims stores the user, the subscription and the raw token. The user is stored under bootstrapify's authorization user key, so its Authorize middleware sees it. Nil claims leave ctx unchanged and a nil user is not stored, because Authorize would call GetID on it.

func TokenFromContext

func TokenFromContext(ctx context.Context) (string, bool)

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims

	User         *User         `json:"User"`
	Subscription *Subscription `json:"subscription,omitempty"`
}

Claims' JSON keys are the wire contract of the user token and must match the claims auth-api signs.

type Subscription

type Subscription struct {
	Tier   string `json:"tier"`
	Status string `json:"status"`
}

func SubscriptionFromContext

func SubscriptionFromContext(ctx context.Context) (*Subscription, bool)

type User

type User struct {
	ID       uuid.UUID `json:"id"`
	Username string    `json:"username,omitempty"`
	Roles    []string  `json:"roles,omitempty"`
}

User is the identity carried in the user token.

func UserFromContext

func UserFromContext(ctx context.Context) (*User, bool)

func (*User) GetID

func (u *User) GetID() uuid.UUID

func (*User) GetRoles

func (u *User) GetRoles() []string

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator validates HS256-signed user tokens. The key is immutable after construction, so a Validator is safe for concurrent use.

func NewValidator

func NewValidator(encodedKey []byte) (*Validator, error)

NewValidator decodes the base64-encoded HS256 key. Like auth-api, it uses the first 32 bytes of the decoded key.

func (*Validator) Validate

func (v *Validator) Validate(token string) (*Claims, error)

Validate parses the token and verifies its HS256 signature and registered claims. A token without an expiry is rejected.

Jump to

Keyboard shortcuts

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