csrf

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCookieName = "csrf_token"
)

Variables

This section is empty.

Functions

func HandleFunc

func HandleFunc(secretKey []byte, opts ...Option) xun.HandleFunc

HandleFunc serves the JavaScript token required for the CSRF middleware.

It takes the secret key and options to customize the behavior. See the Option type for more information.

func New

func New(secretKey []byte, opts ...Option) xun.Middleware

New returns a middleware that generates a CSRF token and validates it in the request.

The opts parameter is a list of Option functions that can be used to customize the behavior of the CSRF middleware. See the Option type for more information.

Types

type Option

type Option func(o *Options)

Option is a function type that takes a pointer to Options and modifies it. It is used to customize the behavior of the CSRF middleware.

func WithCookie

func WithCookie(name string) Option

WithCookie sets the name of the cookie to use for storing the CSRF token. Defaults to "csrf_token".

func WithJsToken

func WithJsToken() Option

WithJsToken enables the JavaScript token feature for CSRF protection.

It sets the JsToken field in the Options struct to true, allowing the middleware to generate and handle CSRF tokens via JavaScript.

type Options

type Options struct {
	SecretKey  []byte
	CookieName string
	JsToken    bool
}

Options represents the configuration for the CSRF middleware. It allows customizing the secret key, cookie name, maximum age, and an expiration function for the CSRF token.

Jump to

Keyboard shortcuts

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