Skip to content

About

Simple HTTP Basic Authentication in Go

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

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

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages