mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(auth): enhance security with token hashing and sync integration
- Add token hash fields to Master and Key models for indexed lookups - Implement SyncService integration in admin and master handlers - Update master key validation with backward-compatible digest lookup - Hash child keys in database and store token digests for Redis sync - Add master metadata sync to Redis for balancer validation - Ensure backward compatibility with legacy rows during migration
This commit is contained in:
@@ -9,10 +9,11 @@ import (
|
||||
|
||||
type AdminHandler struct {
|
||||
masterService *service.MasterService
|
||||
syncService *service.SyncService
|
||||
}
|
||||
|
||||
func NewAdminHandler(masterService *service.MasterService) *AdminHandler {
|
||||
return &AdminHandler{masterService: masterService}
|
||||
func NewAdminHandler(masterService *service.MasterService, syncService *service.SyncService) *AdminHandler {
|
||||
return &AdminHandler{masterService: masterService, syncService: syncService}
|
||||
}
|
||||
|
||||
type CreateMasterRequest struct {
|
||||
@@ -43,6 +44,11 @@ func (h *AdminHandler) CreateMaster(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.syncService.SyncMaster(master); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to sync master key", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, gin.H{
|
||||
"id": master.ID,
|
||||
"name": master.Name,
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
|
||||
type MasterHandler struct {
|
||||
masterService *service.MasterService
|
||||
syncService *service.SyncService
|
||||
}
|
||||
|
||||
func NewMasterHandler(masterService *service.MasterService) *MasterHandler {
|
||||
return &MasterHandler{masterService: masterService}
|
||||
func NewMasterHandler(masterService *service.MasterService, syncService *service.SyncService) *MasterHandler {
|
||||
return &MasterHandler{masterService: masterService, syncService: syncService}
|
||||
}
|
||||
|
||||
type IssueChildKeyRequest struct {
|
||||
@@ -55,6 +56,11 @@ func (h *MasterHandler) IssueChildKey(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.syncService.SyncKey(key); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to sync child key", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, gin.H{
|
||||
"id": key.ID,
|
||||
"key_secret": rawChildKey,
|
||||
|
||||
Reference in New Issue
Block a user