Skip to content

bywan/go-http-basic-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple HTTP Basic Authentication in Go

Travis

This is an implementation of HTTP Basic authentication in Go.

Usage

package main

import (
	"log"
	"net/http"

	auth "github.com/bywan/go-http-basic-auth"
)

func myValidator(username, password string) bool {
	// Here is your validator logic
	return username == "foo" && password == "bar"
}

func main() {
	authenticator := auth.NewAuthenticator(myValidator, "myRealm")
	appHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(204)
	})

	http.Handle("/", authenticator.Wrap(appHandler))
	log.Fatal(http.ListenAndServe(":3000", nil))
}

About

Simple HTTP Basic Authentication in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages