Skip to content

Commit 787d81e

Browse files
committed
[mobile] require password for one-time code generation
1 parent 51b1fb1 commit 787d81e

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

internal/sms-gateway/handlers/mobile.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (h *mobileHandler) patchMessage(device models.Device, c *fiber.Ctx) error {
201201

202202
// @Summary Get one-time code for device registration
203203
// @Description Returns one-time code for device registration
204-
// @Security MobileToken
204+
// @Security ApiAuth
205205
// @Tags Device
206206
// @Accept json
207207
// @Produce json
@@ -210,8 +210,8 @@ func (h *mobileHandler) patchMessage(device models.Device, c *fiber.Ctx) error {
210210
// @Router /mobile/v1/user/code [get]
211211
//
212212
// Get user code
213-
func (h *mobileHandler) getUserCode(device models.Device, c *fiber.Ctx) error {
214-
code, err := h.authSvc.GenerateUserCode(device.UserID)
213+
func (h *mobileHandler) getUserCode(user models.User, c *fiber.Ctx) error {
214+
code, err := h.authSvc.GenerateUserCode(user.ID)
215215
if err != nil {
216216
return err
217217
}
@@ -272,6 +272,12 @@ func (h *mobileHandler) Register(router fiber.Router) {
272272
h.postDevice,
273273
)
274274

275+
router.Get("/user/code",
276+
userauth.NewBasic(h.authSvc),
277+
userauth.UserRequired(),
278+
userauth.WithUser(h.getUserCode),
279+
)
280+
275281
router.Use(
276282
deviceauth.New(h.authSvc),
277283
)
@@ -285,7 +291,6 @@ func (h *mobileHandler) Register(router fiber.Router) {
285291
router.Get("/message", deviceauth.WithDevice(h.getMessage))
286292
router.Patch("/message", deviceauth.WithDevice(h.patchMessage))
287293

288-
router.Get("/user/code", deviceauth.WithDevice(h.getUserCode))
289294
router.Patch("/user/password", deviceauth.WithDevice(h.changePassword))
290295

291296
h.webhooksCtrl.Register(router.Group("/webhooks"))

pkg/swagger/docs/swagger.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@
771771
"get": {
772772
"security": [
773773
{
774-
"MobileToken": []
774+
"ApiAuth": []
775775
}
776776
],
777777
"description": "Returns one-time code for device registration",

pkg/swagger/docs/swagger.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ paths:
935935
schema:
936936
$ref: '#/definitions/smsgateway.ErrorResponse'
937937
security:
938-
- MobileToken: []
938+
- ApiAuth: []
939939
summary: Get one-time code for device registration
940940
tags:
941941
- Device

0 commit comments

Comments
 (0)