Commit graph

3 commits

Author SHA1 Message Date
b91e35a684 Implement authentication with auto token renewal
Add authentication methods to client.go:
- Authenticate(ctx) for explicit login
- AuthenticateWith2FA(ctx, token) for 2FA support
- refreshToken(ctx) for token renewal
- ensureAuthenticated(ctx) for auto-auth before requests
- CurrentUser(ctx) to get logged-in user info
- getToken() for thread-safe token access

Features:
- Token stored with expiry time (23h for safety margin)
- Auto-refresh when token expires within 1 hour
- Falls back to full authentication if refresh fails
- Thread-safe token access using RWMutex
- Sends token via X-Client-Token header

API endpoints used:
- POST /auth/login.json?version=2
- POST /auth/refresh_token.json?version=2
- GET /auth/curr_user.json

Closes checkvist-api-lpn
2026-01-14 13:26:39 +01:00
90c48d9323 Implement Client struct with functional options
Add client.go with:
- Client struct with baseURL, username, remoteKey, token, tokenExp,
  httpClient, retryConf, logger, and sync.RWMutex for thread safety
- NewClient constructor accepting username, remoteKey, and variadic options
- Default values: 30s timeout, Checkvist base URL

Add options.go with:
- RetryConfig struct (MaxRetries, BaseDelay, MaxDelay, Jitter)
- DefaultRetryConfig() with 3 retries, 1s base, 30s max, jitter enabled
- Option type for functional options pattern
- WithHTTPClient, WithTimeout, WithRetryConfig, WithLogger, WithBaseURL

Closes checkvist-api-ymg
2026-01-14 13:25:03 +01:00
3b076836d3 Initial commit 2026-01-14 12:42:00 +01:00