🐛 Bug fixes on factor config
This commit is contained in:
parent
fabde24734
commit
71e959805f
@ -23,9 +23,9 @@ const (
|
|||||||
type AuthFactor struct {
|
type AuthFactor struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
|
|
||||||
Type int8 `json:"type"`
|
Type int8 `json:"type"`
|
||||||
Secret string `json:"-"`
|
Secret string `json:"-"`
|
||||||
Config JSONMap `json:"config"`
|
Config datatypes.JSONMap `json:"config"`
|
||||||
|
|
||||||
Account Account `json:"account"`
|
Account Account `json:"account"`
|
||||||
AccountID uint `json:"account_id"`
|
AccountID uint `json:"account_id"`
|
||||||
|
@ -8,11 +8,9 @@ import (
|
|||||||
"git.solsynth.dev/hypernet/passport/pkg/internal/http/exts"
|
"git.solsynth.dev/hypernet/passport/pkg/internal/http/exts"
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
|
"git.solsynth.dev/hypernet/passport/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
"github.com/pquerna/otp/totp"
|
"github.com/pquerna/otp/totp"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"gorm.io/datatypes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getAvailableFactors(c *fiber.Ctx) error {
|
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)
|
return fmt.Errorf("unable to generate totp key: %v", err)
|
||||||
}
|
}
|
||||||
factor.Secret = key.Secret()
|
factor.Secret = key.Secret()
|
||||||
factor.Config = datatypes.NewJSONType(map[string]any{
|
factor.Config = map[string]any{
|
||||||
"issuer": cfg.Issuer,
|
"issuer": cfg.Issuer,
|
||||||
"account_name": cfg.AccountName,
|
"account_name": cfg.AccountName,
|
||||||
"period": cfg.Period,
|
"period": cfg.Period,
|
||||||
"secret_size": cfg.SecretSize,
|
"secret_size": cfg.SecretSize,
|
||||||
"digits": cfg.Digits,
|
"digits": cfg.Digits,
|
||||||
})
|
}
|
||||||
additionalOnceConfig["url"] = key.URL()
|
additionalOnceConfig["url"] = key.URL()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,19 +134,12 @@ func createFactor(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(additionalOnceConfig) > 0 {
|
if len(additionalOnceConfig) > 0 {
|
||||||
data := factor.Config.Data()
|
|
||||||
for k, v := range additionalOnceConfig {
|
for k, v := range additionalOnceConfig {
|
||||||
data[k] = v
|
factor.Config[k] = v
|
||||||
}
|
}
|
||||||
factor.Config = datatypes.NewJSONType(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var out map[string]any
|
return c.JSON(factor)
|
||||||
raw, _ := jsoniter.Marshal(factor)
|
|
||||||
jsoniter.Unmarshal(raw, &out)
|
|
||||||
out["config"] = factor.Config.Data()
|
|
||||||
|
|
||||||
return c.JSON(out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteFactor(c *fiber.Ctx) error {
|
func deleteFactor(c *fiber.Ctx) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user