fiber/middleware/keyauth
Muhammed Efe Çetin 41866cd3dd
👷 v3 (ci): fix some linter warnings
2023-03-06 17:35:39 +03:00
..
README.md Merge remote-tracking branch 'origin/master' into v3-beta 2022-08-19 14:33:31 +03:00
keyauth.go 👷 v3 (ci): fix some linter warnings 2023-03-06 17:35:39 +03:00
keyauth_test.go v3: include adopter, helmet, keyauth, redirect, rewrite middlewares into the codebase (https://github.com/gofiber/fiber/issues/1828) 2022-06-21 17:36:59 +03: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.Locals("my_token").(string)
    return c.SendString(token)
  })
  
  app.Listen(":3000")
}

Test

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