tokens

package
v0.0.0-...-d30ae71 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// UserPrefix is a common prefix for every user_id caveat
	UserPrefix = "user_id = "
	// TimePrefix is a common prefix for every expiry caveat
	TimePrefix = "time < "
	// Gen is a common caveat for every token
	Gen = "gen = 1"
)

Variables

This section is empty.

Functions

func GenerateLoginToken

func GenerateLoginToken(op TokenOptions) (string, error)

GenerateLoginToken generates a short term login token to be used as token authentication ("m.login.token")

func GetUserFromToken

func GetUserFromToken(token string) (user string, err error)

GetUserFromToken returns the user associated with the token Returns the error if something goes wrong. Warning: Does not validate the token. Use ValidateToken for that.

func ValidateToken

func ValidateToken(op TokenOptions, token string) error

ValidateToken validates that the token is parseable and signed by this server. Returns an error if the token is invalid, otherwise nil.

Types

type TokenOptions

type TokenOptions struct {
	ServerPrivateKey []byte `yaml:"private_key"`
	ServerName       string `yaml:"server_name"`
	UserID           string `json:"user_id"`
	// The valid period of the token in seconds since its generation.
	// Only used in GenerateLoginToken; 0 is treated as defaultDuration.
	Duration int
}

TokenOptions represent parameters of Token

Jump to

Keyboard shortcuts

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