fiber/middleware/keyauth
Dave 2db1858513
🔥 Feature: Add support for custom KeyLookup functions in the Keyauth middleware (#3028)
* port over FallbackKeyLookups from v2 middleware to v3

Signed-off-by: Dave Lee <dave@gray101.com>

* bot pointed out that I missed the format variable

Signed-off-by: Dave Lee <dave@gray101.com>

* fix lint and gofumpt issues

Signed-off-by: Dave Lee <dave@gray101.com>

* major revision: instead of FallbackKeyLookups, expose CustomKeyLookup as function, with utility functions to make creating these easy

Signed-off-by: Dave Lee <dave@gray101.com>

* add more tests to boost coverage

Signed-off-by: Dave Lee <dave@gray101.com>

* teardown code and cleanup

Signed-off-by: Dave Lee <dave@gray101.com>

* test fixes

Signed-off-by: Dave Lee <dave@gray101.com>

* slight boost to test coverage

Signed-off-by: Dave Lee <dave@gray101.com>

* docs: fix md table alignment

* fix comments - change some names, expose functions, improve docs

Signed-off-by: Dave Lee <dave@gray101.com>

* missed one old name

Signed-off-by: Dave Lee <dave@gray101.com>

* fix some suggestions from the bot - error messages, test coverage, mark purely defensive code

Signed-off-by: Dave Lee <dave@gray101.com>

---------

Signed-off-by: Dave Lee <dave@gray101.com>
Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: Jason McNeil <sixcolors@mac.com>
Co-authored-by: RW <rene@gofiber.io>
2024-06-27 20:30:47 +02:00
..
README.md ♻️ v3: fix!: ContextKey collisions (#2781) 2024-01-04 09:44:45 +01:00
config.go 🔥 Feature: Add support for custom KeyLookup functions in the Keyauth middleware (#3028) 2024-06-27 20:30:47 +02:00
keyauth.go 🔥 Feature: Add support for custom KeyLookup functions in the Keyauth middleware (#3028) 2024-06-27 20:30:47 +02:00
keyauth_test.go 🔥 Feature: Add support for custom KeyLookup functions in the Keyauth middleware (#3028) 2024-06-27 20:30:47 +02:00

README.md

Key Authentication

Release Discord Test Security Linter

Special thanks to József Sallai & Ray Mayemir

Install

go get -u github.com/gofiber/fiber/v3
go get -u github.com/gofiber/keyauth/v2

Example

package main

import (
  "github.com/gofiber/fiber/v3"
  "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.TokenFromContext(c) // "" is returned if not found
    return c.SendString(token)
  })
  
  app.Listen(":3000")
}

Test

curl -v --cookie "access_token=hello_world" http://localhost:3000