Skip to content

99designs/basicauth-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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")

About

HTTP basic auth middleware for golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages