transport: Add OAuth Bearer Token HTTP transport authentication type (#5901)
This commit is contained in:
parent
a0be402251
commit
91d6de46cc
2 changed files with 17 additions and 0 deletions
|
|
@ -136,6 +136,8 @@ func (p *HTTP) WithAuth(typ, user, password string) (*HTTP, error) {
|
|||
log.Redact(basicAuth)
|
||||
|
||||
p.Client.Transport = transport.BasicAuth(user, password, p.Client.Transport)
|
||||
case "bearer":
|
||||
p.Client.Transport = transport.BearerAuth(password, p.Client.Transport)
|
||||
case "digest":
|
||||
p.Client.Transport = digest.NewTransport(user, password, p.Client.Transport)
|
||||
default:
|
||||
|
|
|
|||
15
util/transport/bearer.go
Normal file
15
util/transport/bearer.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package transport
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// BearerAuth creates an HTTP transport performing HTTP authorization using an OAuth 2.0 Bearer Token
|
||||
func BearerAuth(token string, base http.RoundTripper) http.RoundTripper {
|
||||
return &Decorator{
|
||||
Decorator: DecorateHeaders(map[string]string{
|
||||
"Authorization": "Bearer " + token,
|
||||
}),
|
||||
Base: base,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue