kanboard-api/auth.go

34 lines
773 B
Go
Raw Normal View History

package kanboard
import "net/http"
// Authenticator applies authentication to HTTP requests.
type Authenticator interface {
Apply(req *http.Request)
}
// apiTokenAuth implements API token authentication.
type apiTokenAuth struct {
user string
token string
}
// Apply adds HTTP Basic Auth with the configured user (or "jsonrpc" if empty) and the API token.
func (a *apiTokenAuth) Apply(req *http.Request) {
user := a.user
if user == "" {
user = "jsonrpc"
}
req.SetBasicAuth(user, a.token)
}
// basicAuth implements username/password authentication.
type basicAuth struct {
username string
password string
}
// Apply adds HTTP Basic Auth with username and password.
func (a *basicAuth) Apply(req *http.Request) {
req.SetBasicAuth(a.username, a.password)
}