keyauth

package module
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 3 Imported by: 11

README

Key Authentication

Release Discord Test Security Linter

Special thanks to József Sallai & Ray Mayemir

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

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

func main() {
  app := fiber.New()
  
  app.Use(keyauth.New(keyauth.Config{
    KeyLookup: "cookie:access_token",
    ContextKey: "my_token"
  }))
  
  app.Get("/", func(c *fiber.Ctx) error {
    token, _ := c.Locals("my_token").(string)
    return c.SendString(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) fiber.Handler

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 fiber.Handler

	// 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 fiber.ErrorHandler

	// 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