rkmidcsrf

package
v2.2.22 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 10 Imported by: 16

Documentation

Overview

Package rkmidcsrf provide auth related options

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeforeCtx

type BeforeCtx struct {
	Input struct {
		UrlPath string
		Method  string
		Token   string
		Request *http.Request
		UserCtx context.Context
	}
	Output struct {
		VaryHeaders []string
		Cookie      *http.Cookie
		ErrResp     rkerror.ErrorInterface
	}
}

BeforeCtx context for Before() function

func NewBeforeCtx

func NewBeforeCtx() *BeforeCtx

NewBeforeCtx create new BeforeCtx with fields initialized

type BootConfig

type BootConfig struct {
	Enabled        bool     `yaml:"enabled" json:"enabled"`
	Ignore         []string `yaml:"ignore" json:"ignore"`
	TokenLength    int      `yaml:"tokenLength" json:"tokenLength"`
	TokenLookup    string   `yaml:"tokenLookup" json:"tokenLookup"`
	CookieName     string   `yaml:"cookieName" json:"cookieName"`
	CookieDomain   string   `yaml:"cookieDomain" json:"cookieDomain"`
	CookiePath     string   `yaml:"cookiePath" json:"cookiePath"`
	CookieMaxAge   int      `yaml:"cookieMaxAge" json:"cookieMaxAge"`
	CookieHttpOnly bool     `yaml:"cookieHttpOnly" json:"cookieHttpOnly"`
	CookieSameSite string   `yaml:"cookieSameSite" json:"cookieSameSite"`
}

BootConfig for YAML

type CsrfExtractor

type CsrfExtractor func(ctx context.Context) (string, error)

type Option

type Option func(*optionSet)

Option

func ToOptions

func ToOptions(config *BootConfig, entryName, entryType string) []Option

ToOptions convert BootConfig into Option list

func WithCookieDomain

func WithCookieDomain(val string) Option

WithCookieDomain provide domain of the CSRF cookie. Optional. Default value "".

func WithCookieHTTPOnly

func WithCookieHTTPOnly(val bool) Option

WithCookieHTTPOnly indicates if CSRF cookie is HTTP only. Optional. Default value false.

func WithCookieMaxAge

func WithCookieMaxAge(val int) Option

WithCookieMaxAge provide max age (in seconds) of the CSRF cookie. Optional. Default value 86400 (24hr).

func WithCookieName

func WithCookieName(val string) Option

WithCookieName provide name of the CSRF cookie. This cookie will store CSRF token. Optional. Default value "csrf".

func WithCookiePath

func WithCookiePath(val string) Option

WithCookiePath provide path of the CSRF cookie. Optional. Default value "".

func WithCookieSameSite

func WithCookieSameSite(val http.SameSite) Option

WithCookieSameSite indicates SameSite mode of the CSRF cookie. Optional. Default value SameSiteDefaultMode.

func WithEntryNameAndType

func WithEntryNameAndType(entryName, entryType string) Option

WithEntryNameAndType provide entry name and entry type.

func WithExtractor

func WithExtractor(ex CsrfExtractor) Option

WithExtractor provide user extractor

func WithMockOptionSet

func WithMockOptionSet(mock OptionSetInterface) Option

WithMockOptionSet provide mock OptionSetInterface

func WithPathToIgnore

func WithPathToIgnore(paths ...string) Option

WithPathToIgnore provide paths prefix that will ignore.

func WithTokenLength

func WithTokenLength(val int) Option

WithTokenLength the length of the generated token. Optional. Default value 32.

func WithTokenLookup

func WithTokenLookup(val string) Option

WithTokenLookup a string in the form of "<source>:<key>" that is used to extract token from the request. Optional. Default value "header:X-CSRF-Token". Possible values: - "header:<name>" - "form:<name>" - "query:<name>" Optional. Default value "header:X-CSRF-Token".

type OptionSetInterface

type OptionSetInterface interface {
	GetEntryName() string

	GetEntryType() string

	Before(*BeforeCtx)

	BeforeCtx(*http.Request) *BeforeCtx

	ShouldIgnore(string) bool
}

OptionSetInterface mainly for testing purpose

func NewOptionSet

func NewOptionSet(opts ...Option) OptionSetInterface

NewOptionSet Create new optionSet with options.

func NewOptionSetMock

func NewOptionSetMock(before *BeforeCtx) OptionSetInterface

NewOptionSetMock for testing purpose

Jump to

Keyboard shortcuts

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