csrf

package
v1.10.91 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 7 Imported by: 0

README

Install

go get -u github.com/gofiber/fiber
go get -u github.com/gofiber/csrf

Example

package main

import (
  "gitee.com/azhai/fiber-u8l"
  "github.com/gofiber/csrf"
)

func main() {
  app := fiber.New()

  app.Get("/", func(c *fiber.Ctx) {
    c.Send(c.Locals("csrf"))
  })

  app.Use(csrf.New())

  app.Post("/register", func(c *fiber.Ctx) {
    c.Send("Welcome!")
  })

  app.Listen(3000)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(configs ...Config) func(*fiber.Ctx)

New ...

Types

type Config

type Config struct {
	// TokenLength is the length of the generated token.
	TokenLength uint8

	// TokenLookup is 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>"
	TokenLookup string

	// Context key to store generated CSRF token into context.
	// Optional. Default value "csrf".
	ContextKey string

	// Name of the CSRF cookie. This cookie will store CSRF token.
	// Optional. Default value "csrf".
	CookieName string

	// Domain of the CSRF cookie.
	// Optional. Default value none.
	CookieDomain string

	// Path of the CSRF cookie.
	// Optional. Default value none.
	CookiePath string

	// Max age (in seconds) of the CSRF cookie.
	// Optional. Default value 86400 (24hr).
	CookieMaxAge int

	// Indicates if CSRF cookie is secure.
	// Optional. Default value false.
	CookieSecure bool

	// Indicates if CSRF cookie is HTTP only.
	// Optional. Default value false.
	CookieHTTPOnly bool
}

Config ...

func FixConfig

func FixConfig(configs []Config) Config

type Extractor

type Extractor func(c *fiber.Ctx) (string, error)

func NewExtractor

func NewExtractor(kind, param string) (extr Extractor)

Jump to

Keyboard shortcuts

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