Add core JSON-RPC 2.0 protocol implementation for Kanboard API: - JSONRPCRequest/Response/Error structs with proper JSON tags - Generic call() method for sending requests and parsing responses - Thread-safe request ID generation using atomic.Int64 - Automatic /jsonrpc.php path appending to baseURL - Support for subdirectory installations - HTTP Basic Auth support (API token and username/password) - Error handling for unauthorized/forbidden responses Includes comprehensive tests with httptest mock server. Closes: kanboard-api-2g1
29 lines
684 B
Go
29 lines
684 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 {
|
|
token string
|
|
}
|
|
|
|
// Apply adds HTTP Basic Auth with username "jsonrpc" and the API token.
|
|
func (a *apiTokenAuth) Apply(req *http.Request) {
|
|
req.SetBasicAuth("jsonrpc", 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)
|
|
}
|