-
Notifications
You must be signed in to change notification settings - Fork 2
/
auth.go
31 lines (26 loc) · 842 Bytes
/
auth.go
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
package httpc
import "net/http"
const authHeaderKey = "Authorization"
// AuthBasic sets parameters to perform basic authentication
func (r *Request) AuthBasic(user, password string) *Request {
r.httpAuthFunc = func(c *http.Request) {
c.SetBasicAuth(user, password)
}
return r
}
// AuthToken sets parameters to perform any token-based authentication, setting
// "Authorization: <prefix> <token>"
func (r *Request) AuthToken(prefix, token string) *Request {
r.httpAuthFunc = func(c *http.Request) {
c.Header.Set(authHeaderKey, prefix+" "+token)
}
return r
}
// AuthBearer sets parameters to perform bearer token authentication, setting
// "Authorization: Bearer <token>"
func (r *Request) AuthBearer(token string) *Request {
r.httpAuthFunc = func(c *http.Request) {
c.Header.Set(authHeaderKey, "Bearer "+token)
}
return r
}