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 ¶
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
Click to show internal directories.
Click to hide internal directories.