fiber-key-auth

fiber api key authentication middleware

Stars
5

Bot releases are visible (Hide)

fiber-key-auth - v0.3.0 Latest Release

Published by github-actions[bot] 6 months ago

Changelog

  • c41d46a chore(deps): update
fiber-key-auth - v0.2.0

Published by github-actions[bot] 7 months ago

feat:

  • optional structured error message (45beb0)

Usage

package main

import (
  "os"

  "github.com/iwpnd/fiber-key-auth"
  "github.com/gofiber/fiber/v2"
)

os.Setenv("API_KEY_TEST", "valid")

func main() {
    app := fiber.New()

    app.Use(keyauth.New(WithStructuredErrorMsg()))

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World 👋!")
    })

    app.Listen(":3000")
}
curl localhost:3000

>> {"message": "no api key"}

curl localhost:3000 -H "x-api-key: invalid"

>> {"message": "invalid api key"}

curl localhost:3000 -H "x-api-key: valid"

>> "Hello, World 👋!"
fiber-key-auth - [v0.2.0]

Published by iwpnd almost 2 years ago

v0.2.0

feat:

  • optional structured error message (45beb0)

Usage

package main

import (
  "os"

  "github.com/iwpnd/fiber-key-auth"
  "github.com/gofiber/fiber/v2"
)

os.Setenv("API_KEY_TEST", "valid")

func main() {
    app := fiber.New()

    app.Use(keyauth.New(WithStructuredErrorMsg()))

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World 👋!")
    })

    app.Listen(":3000")
}
curl localhost:3000

>> {"message": "no api key"}

curl localhost:3000 -H "x-api-key: invalid"

>> {"message": "invalid api key"}

curl localhost:3000 -H "x-api-key: valid"

>> "Hello, World 👋!"
fiber-key-auth - [v0.1.0]: initial release

Published by iwpnd about 3 years ago

About The Project

On deployment inject API keys authorized to use your service. Every call to a private
endpoint of your service has to include a header['x-api-key'] attribute that is
validated against the API keys (starting with: API_KEY_) in your environment.
If it is present, a request is authorized. If it is not fiber returns 401 Unauthorized.
Use this either as a middleware the usage.

Built With

Getting Started

Installation

go get github.com/iwpnd/fiber-key-auth

Usage

As Middleware:

package main

import (
	"os"

	"github.com/iwpnd/fiber-key-auth"
	"github.com/gofiber/fiber/v2"
	)

os.Setenv("API_KEY_TEST", "valid")

func main() {
    app := fiber.New()

    app.Use(keyauth.New())

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World 👋 !")
    })

    app.Listen(":3000")
}

Now try to access your / route.

curl localhost:3000

>> "no api key"

curl localhost:3000 -H "x-api-key: invalid"

>> "invalid api key"

curl localhost:3000 -H "x-api-key: valid"

>> "Hello, World 👋 !"

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Benjamin Ramser - @imwithpanda - [email protected]
Project Link: https://github.com/iwpnd/fiber-key-auth