Files
ez-api/internal/service/admin.go
zenfun 8645b22b83 feat(auth): implement master key authentication system with child key issuance
Add admin and master authentication layers with JWT support. Replace direct
key creation with hierarchical master/child key system. Update database
schema to support master accounts with configurable limits and epoch-based
key revocation. Add health check endpoint with system status monitoring.

BREAKING CHANGE: Removed direct POST /keys endpoint in favor of master-based
key issuance through /v1/tokens. Database migration requires dropping old User
table and creating Master table with new relationships.
2025-12-05 00:16:47 +08:00

25 lines
556 B
Go

package service
import (
"crypto/subtle"
"errors"
"os"
)
type AdminService struct {
adminToken string
}
func NewAdminService() (*AdminService, error) {
token := os.Getenv("EZ_ADMIN_TOKEN")
if token == "" {
return nil, errors.New("EZ_ADMIN_TOKEN environment variable not set")
}
return &AdminService{adminToken: token}, nil
}
// ValidateToken performs a constant-time comparison to prevent timing attacks.
func (s *AdminService) ValidateToken(token string) bool {
return subtle.ConstantTimeCompare([]byte(s.adminToken), []byte(token)) == 1
}