diff --git a/README.md b/README.md index 2fb251c4..a40534d2 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ When creating the SPNEGO client pass the Service Principal Name (SPN) or auto ge object by passing a null string "". ```go r, _ := http.NewRequest("GET", "http://host.test.gokrb5/index.html", nil) -spnegoCl := spngeo.NewClient(cl, nil, "") +spnegoCl := spnego.NewClient(cl, nil, "") resp, err := spnegoCl.Do(r) ``` diff --git a/examples/httpClient.go b/examples/httpClient.go index fc7131ce..a48fe957 100644 --- a/examples/httpClient.go +++ b/examples/httpClient.go @@ -6,10 +6,10 @@ import ( "encoding/hex" "fmt" "io/ioutil" + "log" "net/http" "os" - //"github.com/pkg/profile" "gopkg.in/jcmturner/gokrb5.v7/client" "gopkg.in/jcmturner/gokrb5.v7/config" "gopkg.in/jcmturner/gokrb5.v7/keytab" @@ -42,19 +42,21 @@ const ( ) func main() { + l := log.New(os.Stderr, "GOKRB5 Client: ", log.LstdFlags) + //defer profile.Start(profile.TraceProfile).Stop() // Load the keytab - kb, _ := hex.DecodeString(testdata.TESTUSER1_KEYTAB) + kb, _ := hex.DecodeString(testdata.TESTUSER2_KEYTAB) kt := keytab.New() err := kt.Unmarshal(kb) if err != nil { - panic(err) + l.Fatalf("could not load client keytab: %v", err) } // Load the client krb5 config conf, err := config.NewConfigFromString(kRB5CONF) if err != nil { - panic(err) + l.Fatalf("could not load krb5.conf: %v", err) } addr := os.Getenv("TEST_KDC_ADDR") if addr != "" { @@ -62,34 +64,31 @@ func main() { } // Create the client with the keytab - cl := client.NewClientWithKeytab("testuser1", "TEST.GOKRB5", kt, conf) + cl := client.NewClientWithKeytab("testuser2", "TEST.GOKRB5", kt, conf, client.Logger(l), client.DisablePAFXFAST(true)) // Log in the client err = cl.Login() if err != nil { - panic(err) + l.Fatalf("could not login client: %v", err) } // Form the request url := "http://localhost" + port r, err := http.NewRequest("GET", url, nil) if err != nil { - panic(err) - } - // Apply the client's auth headers to the request - err = spnego.SetSPNEGOHeader(cl, r, "HTTP/host.test.gokrb5") - if err != nil { - panic(err) + l.Fatalf("could create request: %v", err) } + spnegoCl := spnego.NewClient(cl, nil, "HTTP/host.test.gokrb5") + // Make the request - resp, err := http.DefaultClient.Do(r) + resp, err := spnegoCl.Do(r) if err != nil { - panic(err) + l.Fatalf("error making request: %v", err) } b, err := ioutil.ReadAll(resp.Body) if err != nil { - panic(err) + l.Fatalf("error reading response body: %v", err) } fmt.Println(string(b)) }