Phase 2 Week 5: Device Registration & Management

Implement device registration and management system for universal sync.

Database Changes:
- Add device queries to queries.sql (CRUD operations, registration, auth)
- Add sync queue management queries
- Add conflict resolution queries
- Regenerate sqlc models with new device-related types

Device Handler (devices.go):
- InitiateRegistration: Start device registration with auth URL and QR code
- CheckRegistrationStatus: Poll for registration approval
- ListDevices: Get all devices for current user
- GetDevice: Get specific device details
- UpdateDevice: Update device settings (name, sync settings, frequency)
- DeleteDevice: Remove device from account
- ApproveDevice: User approves device registration via web
- RejectDevice: Reject pending device registration
- ListPendingRegistrations: Show all pending registrations
- generateDeviceToken: Generate secure Bearer token for devices

Device Authentication Middleware (device_auth.go):
- Authenticate: Validate device Bearer tokens
- RequirePermission: Check device permissions by type
- hasPermission: Define permissions per device type
- UpdateLastSeen: Auto-update device last_seen timestamp

Configuration:
- Add BaseURL field to Config for device setup URLs

API Endpoints:
POST /api/devices/register - Initiate device registration
POST /api/devices/register/status - Check registration status
GET /api/devices/approve/:id - Approve device (web UI)
POST /api/devices/reject/:id - Reject device
GET /api/devices - List user's devices
GET /api/devices/:id - Get device details
PUT /api/devices/:id - Update device settings
DELETE /api/devices/:id - Delete device
GET /api/devices/pending - List pending registrations

Bruno API Collection:
- Initiate Device Registration
- Check Registration Status
- List Devices
- Get Device
- Update Device
- Delete Device

Dependencies:
- github.com/skip2/go-qrcode for QR code generation

Device Types Supported:
- koreader: Calibre-compatible sync
- kobo: Kobo sync protocol
- web: Web interface
- mobile: Mobile apps

Device Permissions:
- sync:progress
- sync:annotations
- sync:metadata
- device:manage (web only)
This commit is contained in:
2026-01-30 16:45:10 -05:00
parent a2424bcf74
commit 23ad70158c
15 changed files with 1696 additions and 0 deletions
@@ -0,0 +1,17 @@
meta {
name: Check Registration Status
type: http
seq: 2
}
post {
url: {{baseUrl}}/api/devices/register/status
body: json
auth: none
}
body:json {
{
"registration_id": "{{registrationId}}"
}
}
+15
View File
@@ -0,0 +1,15 @@
meta {
name: Delete Device
type: http
seq: 6
}
delete {
url: {{baseUrl}}/api/devices/{{deviceId}}
body: none
auth: bearer
}
headers: {
Authorization: Bearer {{token}}
}
+15
View File
@@ -0,0 +1,15 @@
meta {
name: Get Device
type: http
seq: 4
}
get {
url: {{baseUrl}}/api/devices/{{deviceId}}
body: none
auth: bearer
}
headers: {
Authorization: Bearer {{token}}
}
@@ -0,0 +1,19 @@
meta {
name: Initiate Device Registration
type: http
seq: 1
}
post {
url: {{baseUrl}}/api/devices/register
body: json
auth: none
}
body:json {
{
"device_name": "My Kindle Paperwhite",
"device_type": "koreader",
"device_identifier": "kindle-pw5-hardware-id-12345"
}
}
+15
View File
@@ -0,0 +1,15 @@
meta {
name: List Devices
type: http
seq: 3
}
get {
url: {{baseUrl}}/api/devices
body: none
auth: bearer
}
headers: {
Authorization: Bearer {{token}}
}
+24
View File
@@ -0,0 +1,24 @@
meta {
name: Update Device
type: http
seq: 5
}
put {
url: {{baseUrl}}/api/devices/{{deviceId}}
body: json
auth: bearer
}
headers: {
Authorization: Bearer {{token}}
}
body:json {
{
"device_name": "My Updated Kindle",
"sync_enabled": true,
"auto_sync": true,
"sync_frequency_minutes": 10
}
}