From 71e959805fc9cd064f5ee3c3c8100f4419afa9f8 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 28 Jan 2025 19:33:26 +0800 Subject: [PATCH] :bug: Bug fixes on factor config --- pkg/authkit/models/auth.go | 6 +++--- pkg/internal/http/api/factors_api.go | 17 ++++------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/pkg/authkit/models/auth.go b/pkg/authkit/models/auth.go index 43cbd87..bb8d449 100644 --- a/pkg/authkit/models/auth.go +++ b/pkg/authkit/models/auth.go @@ -23,9 +23,9 @@ const ( type AuthFactor struct { BaseModel - Type int8 `json:"type"` - Secret string `json:"-"` - Config JSONMap `json:"config"` + Type int8 `json:"type"` + Secret string `json:"-"` + Config datatypes.JSONMap `json:"config"` Account Account `json:"account"` AccountID uint `json:"account_id"` diff --git a/pkg/internal/http/api/factors_api.go b/pkg/internal/http/api/factors_api.go index 6469269..910f662 100644 --- a/pkg/internal/http/api/factors_api.go +++ b/pkg/internal/http/api/factors_api.go @@ -8,11 +8,9 @@ import ( "git.solsynth.dev/hypernet/passport/pkg/internal/http/exts" "git.solsynth.dev/hypernet/passport/pkg/internal/services" "github.com/gofiber/fiber/v2" - jsoniter "github.com/json-iterator/go" "github.com/pquerna/otp/totp" "github.com/samber/lo" "github.com/spf13/viper" - "gorm.io/datatypes" ) func getAvailableFactors(c *fiber.Ctx) error { @@ -121,13 +119,13 @@ func createFactor(c *fiber.Ctx) error { return fmt.Errorf("unable to generate totp key: %v", err) } factor.Secret = key.Secret() - factor.Config = datatypes.NewJSONType(map[string]any{ + factor.Config = map[string]any{ "issuer": cfg.Issuer, "account_name": cfg.AccountName, "period": cfg.Period, "secret_size": cfg.SecretSize, "digits": cfg.Digits, - }) + } additionalOnceConfig["url"] = key.URL() } @@ -136,19 +134,12 @@ func createFactor(c *fiber.Ctx) error { } if len(additionalOnceConfig) > 0 { - data := factor.Config.Data() for k, v := range additionalOnceConfig { - data[k] = v + factor.Config[k] = v } - factor.Config = datatypes.NewJSONType(data) } - var out map[string]any - raw, _ := jsoniter.Marshal(factor) - jsoniter.Unmarshal(raw, &out) - out["config"] = factor.Config.Data() - - return c.JSON(out) + return c.JSON(factor) } func deleteFactor(c *fiber.Ctx) error {