Documentation ¶
Overview ¶
package rkmidcsrf provide auth related options
Index ¶
- type BeforeCtx
- type BootConfig
- type CsrfExtractor
- type Option
- func ToOptions(config *BootConfig, entryName, entryType string) []Option
- func WithCookieDomain(val string) Option
- func WithCookieHTTPOnly(val bool) Option
- func WithCookieMaxAge(val int) Option
- func WithCookieName(val string) Option
- func WithCookiePath(val string) Option
- func WithCookieSameSite(val http.SameSite) Option
- func WithEntryNameAndType(entryName, entryType string) Option
- func WithExtractor(ex CsrfExtractor) Option
- func WithIgnorePrefix(paths ...string) Option
- func WithMockOptionSet(mock OptionSetInterface) Option
- func WithTokenLength(val int) Option
- func WithTokenLookup(val string) Option
- type OptionSetInterface
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.ErrorResp } }
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"` IgnorePrefix []string `yaml:"ignorePrefix" json:"ignorePrefix"` 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 Option ¶
type Option func(*optionSet)
Option
func ToOptions ¶
func ToOptions(config *BootConfig, entryName, entryType string) []Option
ToOptions convert BootConfig into Option list
func WithCookieDomain ¶
WithCookieDomain provide domain of the CSRF cookie. Optional. Default value "".
func WithCookieHTTPOnly ¶
WithCookieHTTPOnly indicates if CSRF cookie is HTTP only. Optional. Default value false.
func WithCookieMaxAge ¶
WithCookieMaxAge provide max age (in seconds) of the CSRF cookie. Optional. Default value 86400 (24hr).
func WithCookieName ¶
WithCookieName provide name of the CSRF cookie. This cookie will store CSRF token. Optional. Default value "csrf".
func WithCookiePath ¶
WithCookiePath provide path of the CSRF cookie. Optional. Default value "".
func WithCookieSameSite ¶
WithCookieSameSite indicates SameSite mode of the CSRF cookie. Optional. Default value SameSiteDefaultMode.
func WithEntryNameAndType ¶
WithEntryNameAndType provide entry name and entry type.
func WithExtractor ¶
func WithExtractor(ex CsrfExtractor) Option
WithExtractor provide user extractor
func WithIgnorePrefix ¶
WithIgnorePrefix provide paths prefix that will ignore. Mainly used for swagger main page and RK TV entry.
func WithMockOptionSet ¶
func WithMockOptionSet(mock OptionSetInterface) Option
WithMockOptionSet provide mock OptionSetInterface
func WithTokenLength ¶
WithTokenLength the length of the generated token. Optional. Default value 32.
func WithTokenLookup ¶
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 }
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