mirror of https://github.com/gofiber/fiber.git
* 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> |
||
---|---|---|
.. | ||
README.md | ||
config.go | ||
keyauth.go | ||
keyauth_test.go |
README.md
Key Authentication
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