fiber/middleware/keyauth
nickajacks1 4c68e0242d
ci: address multiple lint rules (#2869)
* ci: explicitly disable tagalign

Tagalign requires awkward manual formatting and doesn't provide much
value for readability.

* ci: enable mirror linter

mirror warns against certain cases of useless conversion between string
and []byte.

* ci: enable perfsprint linter

This linter encourages replacing several functions from the fmt package
with faster alternatives. While fixing issues, I also added a few
exported error types rather than returning a naked errors.New().
2024-02-19 14:33:10 +01:00
..
README.md ♻️ v3: fix!: ContextKey collisions (#2781) 2024-01-04 09:44:45 +01:00
config.go ♻️ v3: fix!: ContextKey collisions (#2781) 2024-01-04 09:44:45 +01:00
keyauth.go v3: Add QueryParser for get query using generic (#2776) 2024-01-19 14:43:44 +01:00
keyauth_test.go ci: address multiple lint rules (#2869) 2024-02-19 14:33:10 +01: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