Skip to content

Commit d97d6cf

Browse files
authored
Use bearer type authorization (#2)
1 parent 955b851 commit d97d6cf

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

directdecisions.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ func NewClient(key string, o *ClientOptions) (c *Client) {
5050
if o == nil {
5151
o = new(ClientOptions)
5252
}
53-
return newClient(httpClientWithTransport(o.HTTPClient, o.BaseURL, func(r *http.Request) {
54-
r.Header.Set("X-Key", key)
55-
}))
53+
authFunc := func(r *http.Request) {}
54+
if key != "" {
55+
authFunc = func(r *http.Request) {
56+
r.Header.Set("Authorization", "Bearer "+key)
57+
}
58+
}
59+
return newClient(httpClientWithTransport(o.HTTPClient, o.BaseURL, authFunc))
5660
}
5761

5862
// newClient constructs a new *Client with the provided http Client, which

directdecisions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
)
2020

2121
func TestClient_key(t *testing.T) {
22-
client, mux, _ := newClient(t, "myauthkey")
22+
client, mux, _ := newClient(t, "xapp-1-my-authkey")
2323

2424
mux.HandleFunc("/v1/votings", requireMethod("POST", func(w http.ResponseWriter, r *http.Request) {
25-
if r.Header.Get("X-Key") != "myauthkey" {
25+
if r.Header.Get("Authorization") != "Bearer xapp-1-my-authkey" {
2626
w.WriteHeader(http.StatusUnauthorized)
2727
return
2828
}

0 commit comments

Comments
 (0)