// +build examples package main import ( "encoding/hex" "fmt" "log" "net/http" "os" goidentity "gopkg.in/jcmturner/goidentity.v3" "gopkg.in/jcmturner/gokrb5.v6/keytab" "gopkg.in/jcmturner/gokrb5.v6/service" "gopkg.in/jcmturner/gokrb5.v6/testdata" ) const ( port = ":9080" ) func main() { //defer profile.Start(profile.TraceProfile).Stop() // Create logger l := log.New(os.Stderr, "GOKRB5 Service: ", log.Ldate|log.Ltime|log.Lshortfile) // Load the service's keytab b, _ := hex.DecodeString(testdata.HTTP_KEYTAB) kt, _ := keytab.Parse(b) // Create the application's specific handler th := http.HandlerFunc(testAppHandler) // Set up handler mappings wrapping in the SPNEGOKRB5Authenticate handler wrapper mux := http.NewServeMux() c := service.NewConfig(kt) mux.Handle("/", service.SPNEGOKRB5Authenticate(th, c, l)) // Start up the web server log.Fatal(http.ListenAndServe(port, mux)) } // Simple application specific handler func testAppHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) ctx := r.Context() creds := ctx.Value(service.CTXKeyCredentials).(goidentity.Identity) fmt.Fprintf(w, `

GOKRB5 Handler