jwt

package
v0.0.0-...-0e46d6e Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 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
)

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"`

	// 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 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) 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