Skip to content

Commit 30f9156

Browse files
committed
[api] migrate from apikey to keyauth
1 parent 34fbb47 commit 30f9156

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

internal/sms-gateway/handlers/mobile.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/auth"
1414
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/devices"
1515
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/messages"
16-
"github.com/capcom6/go-infra-fx/http/apikey"
1716
"github.com/go-playground/validator/v10"
1817
"github.com/gofiber/fiber/v2"
18+
"github.com/gofiber/fiber/v2/middleware/keyauth"
1919
"github.com/gofiber/fiber/v2/middleware/limiter"
2020
"github.com/jaevor/go-nanoid"
2121
"go.uber.org/fx"
@@ -181,12 +181,17 @@ func (h *mobileHandler) patchMessage(device models.Device, c *fiber.Ctx) error {
181181
func (h *mobileHandler) Register(router fiber.Router) {
182182
router = router.Group("/mobile/v1")
183183

184-
router.Post("/device", limiter.New(), apikey.New(apikey.Config{
185-
Next: func(c *fiber.Ctx) bool { return h.authSvc.IsPublic() },
186-
Authorizer: func(token string) bool {
187-
return h.authSvc.AuthorizeRegistration(token) == nil
188-
},
189-
}), h.postDevice)
184+
router.Post("/device",
185+
limiter.New(),
186+
keyauth.New(keyauth.Config{
187+
Next: func(c *fiber.Ctx) bool { return h.authSvc.IsPublic() },
188+
Validator: func(c *fiber.Ctx, token string) (bool, error) {
189+
err := h.authSvc.AuthorizeRegistration(token)
190+
return err == nil, err
191+
},
192+
}),
193+
h.postDevice,
194+
)
190195

191196
router.Use(func(c *fiber.Ctx) (err error) {
192197
header := c.Get(fiber.HeaderAuthorization)

0 commit comments

Comments
 (0)