Skip to content

Commit

Permalink
update client example and fix readme typo
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmturner committed Feb 23, 2019
1 parent 08f6f69 commit 95f6d33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand Down
29 changes: 14 additions & 15 deletions examples/httpClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -42,54 +42,53 @@ 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 != "" {
conf.Realms[0].KDC = []string{addr + ":88"}
}

// 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))
}

0 comments on commit 95f6d33

Please sign in to comment.