🐛 Bug fixes on factor config

This commit is contained in:
LittleSheep 2025-01-28 19:33:26 +08:00
parent fabde24734
commit 71e959805f
2 changed files with 7 additions and 16 deletions

View File

@ -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"`

View File

@ -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 {