Passport/pkg/server/factors.go

27 lines
691 B
Go
Raw Normal View History

2024-01-06 17:56:32 +00:00
package server
import (
"code.smartsheep.studio/hydrogen/bus/pkg/kit/adaptor"
"code.smartsheep.studio/hydrogen/bus/pkg/kit/publisher"
"code.smartsheep.studio/hydrogen/bus/pkg/wire"
"code.smartsheep.studio/hydrogen/passport/pkg/security"
"code.smartsheep.studio/hydrogen/passport/pkg/services"
)
func getFactorToken(c *publisher.RequestCtx) error {
data := adaptor.ParseAnyToStruct[struct {
ID uint `json:"id"`
}](c.Parameters)
factor, err := services.LookupFactor(data.ID)
if err != nil {
return c.SendError(wire.InvalidActions, err)
}
if err := security.GetFactorCode(factor); err != nil {
return c.SendError(wire.InvalidActions, err)
}
return c.SendResponse(nil)
}