gowebdav/basicAuth.go

54 lines
1.3 KiB
Go
Raw Normal View History

package gowebdav
import (
"fmt"
2024-01-20 11:27:24 +01:00
"log"
"net/http"
)
// BasicAuth structure holds our credentials
type BasicAuth struct {
user string
pw string
}
2024-01-20 12:18:22 +01:00
// NewDigestAuth creates a new instance of our Digest Authenticator
func NewBasicAuth(login, secret string) (Authenticator, error) {
return &BasicAuth{user: login, pw: secret}, nil
}
// Authorize the current request
func (b *BasicAuth) Authorize(c *http.Client, rq *http.Request, path string) error {
rq.SetBasicAuth(b.user, b.pw)
2024-01-20 11:27:24 +01:00
log.Printf("BasicAuth.Authorize : SetBasicAuth(%s, %s)", b.user, b.pw)
return nil
}
// Verify verifies if the authentication
func (b *BasicAuth) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) {
2024-01-20 11:27:24 +01:00
log.Printf("BasicAuth.Verify : StatusCode = %d", rs.StatusCode)
if rs.StatusCode == 401 {
err = NewPathError("Authorize", path, rs.StatusCode)
}
return
}
// Close cleans up all resources
func (b *BasicAuth) Close() error {
2024-01-20 11:27:24 +01:00
log.Printf("BasicAuth.Close")
return nil
}
// Clone creates a Copy of itself
func (b *BasicAuth) Clone() Authenticator {
2024-01-20 11:27:24 +01:00
log.Printf("BasicAuth.Clone")
// no copy due to read only access
return b
}
// String toString
func (b *BasicAuth) String() string {
2024-01-20 11:27:24 +01:00
log.Printf("BasicAuth.String")
return fmt.Sprintf("BasicAuth login: %s", b.user)
}