- Add user field to apiTokenAuth struct - Add WithAPITokenUser(token, user) method for custom username - Default to "jsonrpc" when no user specified (backward compatible) - Add tests for custom user and empty user scenarios Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
34 lines
773 B
Go
34 lines
773 B
Go
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)
|
|
}
|