Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/pkg/gowebdav/basicAuth.go
1560 views
1
package gowebdav
2
3
import (
4
"encoding/base64"
5
"net/http"
6
)
7
8
// BasicAuth structure holds our credentials
9
type BasicAuth struct {
10
user string
11
pw string
12
}
13
14
// Type identifies the BasicAuthenticator
15
func (b *BasicAuth) Type() string {
16
return "BasicAuth"
17
}
18
19
// User holds the BasicAuth username
20
func (b *BasicAuth) User() string {
21
return b.user
22
}
23
24
// Pass holds the BasicAuth password
25
func (b *BasicAuth) Pass() string {
26
return b.pw
27
}
28
29
// Authorize the current request
30
func (b *BasicAuth) Authorize(req *http.Request, method string, path string) {
31
a := b.user + ":" + b.pw
32
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
33
req.Header.Set("Authorization", auth)
34
}
35
36