forked from baron/baron-sso
클라이언트 시크릿키 GET 요청 우회
This commit is contained in:
@@ -226,7 +226,7 @@ func main() {
|
||||
auditHandler := handler.NewAuditHandler(auditRepo)
|
||||
authHandler := handler.NewAuthHandler(redisService, idpProvider, auditRepo)
|
||||
adminHandler := handler.NewAdminHandler()
|
||||
devHandler := handler.NewDevHandler()
|
||||
devHandler := handler.NewDevHandler(redisService)
|
||||
tenantHandler := handler.NewTenantHandler(db)
|
||||
kratosAdminService := service.NewKratosAdminService()
|
||||
oryAdminProvider := service.NewOryProvider()
|
||||
|
||||
@@ -12,11 +12,13 @@ import (
|
||||
|
||||
type DevHandler struct {
|
||||
Hydra *service.HydraAdminService
|
||||
Redis *service.RedisService
|
||||
}
|
||||
|
||||
func NewDevHandler() *DevHandler {
|
||||
func NewDevHandler(redis *service.RedisService) *DevHandler {
|
||||
return &DevHandler{
|
||||
Hydra: service.NewHydraAdminService(),
|
||||
Redis: redis,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +104,7 @@ func (h *DevHandler) ListClients(c *fiber.Ctx) error {
|
||||
|
||||
items := make([]clientSummary, 0, len(clients))
|
||||
for _, client := range clients {
|
||||
items = append(items, mapClientSummary(client))
|
||||
items = append(items, h.mapClientSummary(client))
|
||||
}
|
||||
|
||||
return c.JSON(clientListResponse{
|
||||
@@ -126,7 +128,7 @@ func (h *DevHandler) GetClient(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
|
||||
summary := mapClientSummary(*client)
|
||||
summary := h.mapClientSummary(*client)
|
||||
return c.JSON(clientDetailResponse{
|
||||
Client: summary,
|
||||
Endpoints: clientEndpoints{
|
||||
@@ -165,7 +167,7 @@ func (h *DevHandler) UpdateClientStatus(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
|
||||
summary := mapClientSummary(*updated)
|
||||
summary := h.mapClientSummary(*updated)
|
||||
return c.JSON(clientDetailResponse{
|
||||
Client: summary,
|
||||
Endpoints: clientEndpoints{
|
||||
@@ -251,9 +253,14 @@ func (h *DevHandler) CreateClient(c *fiber.Ctx) error {
|
||||
}
|
||||
created.Metadata["client_secret"] = created.ClientSecret
|
||||
_, _ = h.Hydra.UpdateClient(c.Context(), created.ClientID, *created)
|
||||
|
||||
// Also store in Redis if available
|
||||
if h.Redis != nil {
|
||||
_ = h.Redis.Set("client_secret:"+created.ClientID, created.ClientSecret, 0)
|
||||
}
|
||||
}
|
||||
|
||||
summary := mapClientSummary(*created)
|
||||
summary := h.mapClientSummary(*created)
|
||||
return c.Status(fiber.StatusCreated).JSON(clientDetailResponse{
|
||||
Client: summary,
|
||||
Endpoints: clientEndpoints{
|
||||
@@ -341,7 +348,7 @@ func (h *DevHandler) UpdateClient(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
|
||||
summary := mapClientSummary(*updatedClient)
|
||||
summary := h.mapClientSummary(*updatedClient)
|
||||
return c.JSON(clientDetailResponse{
|
||||
Client: summary,
|
||||
Endpoints: clientEndpoints{
|
||||
@@ -367,6 +374,11 @@ func (h *DevHandler) DeleteClient(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
|
||||
// Clean up Redis
|
||||
if h.Redis != nil {
|
||||
_ = h.Redis.Delete("client_secret:" + clientID)
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
@@ -416,7 +428,7 @@ func (h *DevHandler) RevokeConsents(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
func mapClientSummary(client service.HydraClient) clientSummary {
|
||||
func (h *DevHandler) mapClientSummary(client service.HydraClient) clientSummary {
|
||||
status := "active"
|
||||
if client.Metadata != nil {
|
||||
if value, ok := client.Metadata["status"].(string); ok && strings.ToLower(value) == "inactive" {
|
||||
@@ -436,6 +448,20 @@ func mapClientSummary(client service.HydraClient) clientSummary {
|
||||
|
||||
scopes := strings.Fields(client.Scope)
|
||||
|
||||
clientSecret := client.ClientSecret
|
||||
// 1. Check Metadata (Legacy/Fallback)
|
||||
if clientSecret == "" && client.Metadata != nil {
|
||||
if val, ok := client.Metadata["client_secret"].(string); ok {
|
||||
clientSecret = val
|
||||
}
|
||||
}
|
||||
// 2. Check Redis (New)
|
||||
if clientSecret == "" && h.Redis != nil {
|
||||
if val, err := h.Redis.Get("client_secret:" + client.ClientID); err == nil && val != "" {
|
||||
clientSecret = val
|
||||
}
|
||||
}
|
||||
|
||||
return clientSummary{
|
||||
ID: client.ClientID,
|
||||
Name: name,
|
||||
@@ -443,7 +469,7 @@ func mapClientSummary(client service.HydraClient) clientSummary {
|
||||
Status: status,
|
||||
RedirectURIs: client.RedirectURIs,
|
||||
Scopes: scopes,
|
||||
ClientSecret: client.ClientSecret,
|
||||
ClientSecret: clientSecret,
|
||||
Metadata: client.Metadata,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user