Documentation
¶
Index ¶
- Variables
- func CsrfFromForm(param string) func(ctx context.Context, c *app.RequestContext) (string, error)
- func CsrfFromHeader(param string) func(ctx context.Context, c *app.RequestContext) (string, error)
- func CsrfFromParam(param string) func(ctx context.Context, c *app.RequestContext) (string, error)
- func CsrfFromQuery(param string) func(ctx context.Context, c *app.RequestContext) (string, error)
- func GetToken(c *app.RequestContext) string
- func New(opts ...Option) app.HandlerFunc
- type CsrfExtractorHandler
- type CsrfNextHandler
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var OptionsDefault = Options{ Secret: csrfSecret, IgnoreMethods: []string{"GET", "HEAD", "OPTIONS", "TRACE"}, Next: nil, KeyLookup: "header:" + csrfHeaderName, ErrorFunc: func(ctx context.Context, c *app.RequestContext) { panic(c.Errors.Last()) }, }
OptionsDefault is the default options.
Functions ¶
func CsrfFromForm ¶
CsrfFromForm returns a function that extracts a token from a multipart-form.
func CsrfFromHeader ¶
CsrfFromHeader returns a function that extracts token from the request header.
func CsrfFromParam ¶
CsrfFromParam returns a function that extracts token from the url param string.
func CsrfFromQuery ¶
CsrfFromQuery returns a function that extracts token from the query string.
Types ¶
type CsrfExtractorHandler ¶
type CsrfNextHandler ¶
type CsrfNextHandler func(ctx context.Context, c *app.RequestContext) bool
type Option ¶
type Option struct {
F func(o *Options)
}
Option is the only struct that can be used to set Options.
func WithExtractor ¶
func WithExtractor(f CsrfExtractorHandler) Option
WithExtractor sets extractor.
func WithIgnoredMethods ¶
WithIgnoredMethods sets methods that do not need to be protected.
func WithKeyLookUp ¶
WithKeyLookUp sets a string in the form of "<source>:<key>" that is used to create an Extractor that extracts the token from the request.
func WithNext ¶
func WithNext(f CsrfNextHandler) Option
WithNext sets whether to skip this middleware.
type Options ¶
type Options struct {
// Secret used to generate token.
//
// Default: csrfSecret
Secret string
// Ignored methods will be considered no protection required.
//
// Optional. Default: "GET", "HEAD", "OPTIONS", "TRACE"
IgnoreMethods []string
// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next CsrfNextHandler
// KeyLookup is a string in the form of "<source>:<key>" that is used
// to create an Extractor that extracts the token from the request.
// Possible values:
// - "header:<name>"
// - "query:<name>"
// - "param:<name>"
// - "form:<name>"
//
// Optional. Default: "header:X-CSRF-TOKEN"
KeyLookup string
// ErrorFunc is executed when an error is returned from app.HandlerFunc.
//
// Optional. Default: func(ctx context.Context, c *app.RequestContext) { panic(c.Errors.Last()) }
ErrorFunc app.HandlerFunc
// Extractor returns the csrf token.
//
// If set this will be used in place of an Extractor based on KeyLookup.
//
// Optional. Default will create an Extractor based on KeyLookup.
Extractor CsrfExtractorHandler
}
Options defines the config for middleware.