Files
pad/internal/models/api_token.go
T
xarmian cf83a60fc2 feat: Add API tokens system for programmatic access
Add a complete API tokens system enabling CI/CD integrations, custom
scripts, and third-party tools to authenticate with the Pad API.

- Migration 011: api_tokens table with hash-based token storage
- Model: APIToken, APITokenCreate, APITokenWithSecret types
- Store: CRUD operations with crypto/rand generation and SHA-256 hashing
- Middleware: Bearer token auth that sets workspace context
- Handlers: POST/GET/DELETE /workspaces/{ws}/tokens endpoints
- CORS: Allow Authorization header for token-based requests
2026-03-28 14:13:50 +00:00

29 lines
879 B
Go

package models
import "time"
// APIToken represents a stored API token (without the secret).
type APIToken struct {
ID string `json:"id"`
WorkspaceID string `json:"workspace_id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Scopes string `json:"scopes"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
// APITokenCreate is the input for creating a new API token.
type APITokenCreate struct {
Name string `json:"name"`
Scopes string `json:"scopes,omitempty"`
}
// APITokenWithSecret is returned only on creation and includes the
// plaintext token. The token is never stored and cannot be retrieved again.
type APITokenWithSecret struct {
APIToken
Token string `json:"token"` // Only returned once
}