package xsrftoken
import "golang.org/x/net/xsrftoken"
Package xsrftoken provides methods for generating and validating secure XSRF tokens.
Index ¶
- Constants
- func Generate(key, userID, actionID string) string
- func Valid(token, key, userID, actionID string) bool
- func ValidFor(token, key, userID, actionID string, timeout time.Duration) bool
Constants ¶
Timeout is the duration for which XSRF tokens are valid. It is exported so clients may set cookie timeouts that match generated tokens.
Functions ¶
func Generate ¶
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 ¶
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 ¶
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.
Source Files ¶
xsrf.go
- Version
- v0.35.0 (latest)
- Published
- Feb 10, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 5 minutes ago –
Tools for package owners.