2018-04-07 15:37:48 +02:00
|
|
|
package gowebdav
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
2020-08-18 04:47:58 +02:00
|
|
|
"net/http"
|
2018-04-07 15:37:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// BasicAuth structure holds our credentials
|
|
|
|
type BasicAuth struct {
|
|
|
|
user string
|
|
|
|
pw string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type identifies the BasicAuthenticator
|
|
|
|
func (b *BasicAuth) Type() string {
|
|
|
|
return "BasicAuth"
|
|
|
|
}
|
|
|
|
|
|
|
|
// User holds the BasicAuth username
|
|
|
|
func (b *BasicAuth) User() string {
|
|
|
|
return b.user
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass holds the BasicAuth password
|
|
|
|
func (b *BasicAuth) Pass() string {
|
|
|
|
return b.pw
|
|
|
|
}
|
|
|
|
|
|
|
|
// Authorize the current request
|
2020-08-18 04:47:58 +02:00
|
|
|
func (b *BasicAuth) Authorize(req *http.Request, method string, path string) {
|
2018-04-07 15:37:48 +02:00
|
|
|
a := b.user + ":" + b.pw
|
|
|
|
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
|
2020-08-18 04:47:58 +02:00
|
|
|
req.Header.Set("Authorization", auth)
|
2018-04-07 15:37:48 +02:00
|
|
|
}
|