feat(api): /devices register + paseto v4 (middleware Bearer, bootstrap mobile du token)

This commit is contained in:
m
2026-09-10 07:25:11 +02:00
parent bdf1fadce9
commit caa6e6483c
18 changed files with 407 additions and 27 deletions
+29 -1
View File
@@ -1,8 +1,36 @@
package handlers
import (
"regexp"
"github.com/gin-gonic/gin"
"github.com/vaultdrop/backend/pkg/api"
)
func DevicesRegister(c *gin.Context) { api.NotImplemented(c) }
var deviceIDPattern = regexp.MustCompile(`^[0-9a-f]{32}$`)
type DeviceRegisterRequest struct {
DeviceID string `json:"deviceId"`
}
func DevicesRegister(c *gin.Context) {
var req DeviceRegisterRequest
if err := c.ShouldBindJSON(&req); err != nil || req.DeviceID == "" {
api.Error(c, 400, "INVALID_REQUEST", "missing deviceId")
return
}
if !deviceIDPattern.MatchString(req.DeviceID) {
api.Error(c, 400, "INVALID_DEVICE_ID", "deviceId must be 32 lowercase hex chars")
return
}
token, err := Auth.Issue(req.DeviceID)
if err != nil {
api.Error(c, 500, "TOKEN_ERROR", "could not issue token")
return
}
api.OK(c, gin.H{"deviceId": req.DeviceID, "token": token})
}