keyauth

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 3 Imported by: 1

README

Key Authentication

Release Discord Test Security Linter

Special thanks to József Sallai & Ray Mayemir

Install
go get -u github.com/gofiber/fiber
go get -u github.com/gofiber/keyauth
Example
package main

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/keyauth"
)

func main() {
  app := fiber.New()
  
  app.Use(keyauth.New(keyauth.Config{
    TokenLookup: "cookie:access_token",
    ContextKey: "my_token"
  }))
  
  app.Get("/", func(c *fiber.Ctx) {
    c.Send(c.Locals("my_token"))
  })
  
  app.Listen(3000)
}
Test
curl -v --cookie "access_token=hello_world" http://localhost:3000

Documentation

Overview

🚀 Fiber is an Express inspired web framework written in Go with 💖 📌 API Documentation: https://fiber.wiki 📝 Github Repository: https://github.com/gofiber/fiber Special thanks to Echo: https://github.com/labstack/echo/blob/master/middleware/key_auth.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New ...

Types

type Config

type Config struct {
	// Filter defines a function to skip middleware.
	// Optional. Default: nil
	Filter func(*fiber.Ctx) bool

	// SuccessHandler defines a function which is executed for a valid key.
	// Optional. Default: nil
	SuccessHandler func(*fiber.Ctx)

	// ErrorHandler defines a function which is executed for an invalid key.
	// It may be used to define a custom error.
	// Optional. Default: 401 Invalid or expired key
	ErrorHandler func(*fiber.Ctx, error)

	// KeyLookup is a string in the form of "<source>:<name>" that is used
	// to extract key from the request.
	// Optional. Default value "header:Authorization".
	// Possible values:
	// - "header:<name>"
	// - "query:<name>"
	// - "form:<name>"
	// - "param:<name>"
	// - "cookie:<name>"
	KeyLookup string

	// AuthScheme to be used in the Authorization header.
	// Optional. Default value "Bearer".
	AuthScheme string

	// Validator is a function to validate key.
	// Optional. Default: nil
	Validator func(*fiber.Ctx, string) (bool, error)

	// Context key to store the bearertoken from the token into context.
	// Optional. Default: "token".
	ContextKey string
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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