/usr/share/doc/golang-github-abbot-go-http-auth-dev/examples/wrapped.go is in golang-github-abbot-go-http-auth-dev 0.0~git20150714.0.46b9627-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | // +build ignore
/*
Example demonstrating how to wrap an application which is unaware of
authenticated requests with a "pass-through" authentication
Build with:
go build wrapped.go
*/
package main
import (
auth ".."
"fmt"
"net/http"
)
func Secret(user, realm string) string {
if user == "john" {
// password is "hello"
return "$1$dlPL2MqE$oQmn16q49SqdmhenQuNgs1"
}
return ""
}
func regular_handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<html><body><h1>This application is unaware of authentication</h1></body></html>")
}
func main() {
authenticator := auth.NewBasicAuthenticator("example.com", Secret)
http.HandleFunc("/", auth.JustCheck(authenticator, regular_handler))
http.ListenAndServe(":8080", nil)
}
|