Add Authenticator interface and Digest auth support

This commit is contained in:
David
2018-04-07 08:37:48 -05:00
committed by Christoph Polcin
parent 5bedad6f1e
commit 6d8c168f72
4 changed files with 166 additions and 13 deletions

33
basicAuth.go Normal file
View File

@@ -0,0 +1,33 @@
package gowebdav
import (
"encoding/base64"
)
// 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
func (b *BasicAuth) Authorize(c *Client, method string, path string) {
a := b.user + ":" + b.pw
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
c.headers.Set("Authorization", auth)
}