jwt

package
v0.0.0-...-cdbae23 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Webcam restrictions.
	NoVideoRule     = Rule("novideo")     // Can not use video features at all
	NoBroadcastRule = Rule("nobroadcast") // They can not share their webcam
	NoImageRule     = Rule("noimage")     // Can not upload or see images
	RedCamRule      = Rule("redcam")      // Their camera is force marked NSFW
	NoDarkVideoRule = Rule("nodvd")       // Exempt user from the dark video detector
)

Available Rules your site can include in the JWT token: to enforce moderator rules on the user logging into chat.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	// Custom claims.
	IsAdmin    bool   `json:"op,omitempty"`
	VIP        bool   `json:"vip,omitempty"`
	Avatar     string `json:"img,omitempty"`
	ProfileURL string `json:"url,omitempty"`
	Nick       string `json:"nick,omitempty"`
	Emoji      string `json:"emoji,omitempty"`
	Gender     string `json:"gender,omitempty"`
	Rules      Rules  `json:"rules,omitempty"`
	Flair      Flair  `json:"flair,omitempty"`

	// Standard claims. Notes:
	// subject = username
	jwt.RegisteredClaims
}

Custom JWT Claims.

func ParseAndValidate

func ParseAndValidate(tokenStr string) (*Claims, bool, error)

ParseAndValidate returns the Claims, a boolean authOK, and any errors.

func (Claims) ReSign

func (c Claims) ReSign() (string, error)

ReSign will sign a new JWT token for existing claims. The chat server does this to send refreshed tokens to the front-end so the server can reboot gracefully, clients reconnect and not be told their auth had expired. New token expires after 5 minutes.

func (Claims) ToJSON

func (c Claims) ToJSON() template.JS

ToJSON serializes the claims to JavaScript.

type Flair

type Flair struct {
	// Plain text of the flair, e.g. "Newbie"
	Name string `json:"name,omitempty"`

	// Bulma CSS color class for the flair icon and tag color in Profile Cards.
	// One of: info, success, warning, danger, private
	// Gets composed into class names e.g.: has-text-info, is-info
	Color string `json:"color,omitempty"`

	// FontAwesome CSS classes for the icon.
	// e.g.: "fa fa-star"
	// Default: "fa fa-star"
	Icon string `json:"icon,omitempty"`

	// NoVIP boolean: if set on a user with VIP status, their VIP flair is hidden from display.
	// Other custom Flair properties may still show. If the Flair has only NoVIP set but everything
	// else empty, then no VIP and no custom flair will show.
	NoVIP bool `json:"noVIP,omitempty"`
}

Flair adds an optional custom icon and decoration to users on chat (e.g. like VIP but no special features).

type Rule

type Rule string

Rule options for the JWT custom key.

Safely check its settings with the Is() functions which handle superset rules which imply other rules, for example novideo > nobroadcast.

func (Rule) IsNoBroadcastRule

func (r Rule) IsNoBroadcastRule() bool

func (Rule) IsNoDarkVideoRule

func (r Rule) IsNoDarkVideoRule() bool

func (Rule) IsNoImageRule

func (r Rule) IsNoImageRule() bool

func (Rule) IsNoVideoRule

func (r Rule) IsNoVideoRule() bool

func (Rule) IsRedCamRule

func (r Rule) IsRedCamRule() bool

type Rules

type Rules []Rule

Rules are the plural set of rules as shown on a JWT token (string array), with some extra functionality attached such as an easy serializer to JSON.

func (Rules) ToDict

func (r Rules) ToDict() map[string]bool

ToDict serializes a Rules string-array into a map of the Is* functions, for easy front-end access to the currently enabled rules.

Jump to

Keyboard shortcuts

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