xsrftoken

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: BSD-3-Clause Imports: 8 Imported by: 106

Documentation

Overview

Package xsrftoken provides methods for generating and validating secure XSRF tokens.

Index

Constants

View Source
const Timeout = 24 * time.Hour

Timeout is the duration for which XSRF tokens are valid. It is exported so clients may set cookie timeouts that match generated tokens.

Variables

This section is empty.

Functions

func Generate

func Generate(key, userID, actionID string) string

Generate returns a URL-safe secure XSRF token that expires in 24 hours.

key is a secret key for your application; it must be non-empty. userID is an optional unique identifier for the user. actionID is an optional action the user is taking (e.g. POSTing to a particular path).

func Valid

func Valid(token, key, userID, actionID string) bool

Valid reports whether a token is a valid, unexpired token returned by Generate. The token is considered to be expired and invalid if it is older than the default Timeout.

func ValidFor

func ValidFor(token, key, userID, actionID string, timeout time.Duration) bool

ValidFor reports whether a token is a valid, unexpired token returned by Generate. The token is considered to be expired and invalid if it is older than the timeout duration.

Types

This section is empty.

Jump to

Keyboard shortcuts

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