basicauth

package module
v0.0.0-...-bf6f9cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 6 Imported by: 6

README

basicauth-go

GoDoc Build Status

golang middleware for HTTP basic auth.

// Chi

router.Use(basicauth.New("MyRealm", map[string][]string{
    "bob": {"password1", "password2"},
}))


// Manual wrapping

middleware := basicauth.New("MyRealm", map[string][]string{
    "bob": {"password1", "password2"},
})

h := middlware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request)) {
    /// do stuff
})

log.Fatal(http.ListenAndServe(":8080", h))
env loading

If your environment looks like this:

SOME_PREFIX_BOB=password
SOME_PREFIX_JANE=password1,password2

you can load it like this:

middleware := basicauth.NewFromEnv("MyRealm", "SOME_PREFIX")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(realm string, credentials map[string][]string) func(http.Handler) http.Handler

New returns a piece of middleware that will allow access only if the provided credentials match within the given service otherwise it will return a 401 and not call the next handler.

func NewFromEnv

func NewFromEnv(realm, prefix string) func(http.Handler) http.Handler

NewFromEnv reads a set of credentials in from environment variables in the format {PREFIX}{USERNAME|tolower}=password1,password2 and returns middleware that will validate incoming requests.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL