88 lines
3.3 KiB
Go
88 lines
3.3 KiB
Go
|
package controllers
|
|||
|
|
|||
|
import (
|
|||
|
"amocrm/internal/service"
|
|||
|
"amocrm/internal/tools"
|
|||
|
"fmt"
|
|||
|
"github.com/gofiber/fiber/v2"
|
|||
|
"go.uber.org/zap"
|
|||
|
)
|
|||
|
|
|||
|
// todo под битриск переписать надо
|
|||
|
|
|||
|
// контроллер на который редиректятся ответы по авторизации битрикса
|
|||
|
func (c *WebhookController) WebhookCreate(ctx *fiber.Ctx) error {
|
|||
|
code := ctx.Query("code") // первый авторизационный код
|
|||
|
domain := ctx.Query("domain") // домен портала, на котором происходит авторизация
|
|||
|
state := ctx.Query("state") // строка которая передавалась в соц аус сервисе
|
|||
|
scope := ctx.Query("scope") // разделенный запятыми список прав доступа к REST API, которые портал предоставляет приложению
|
|||
|
member_id := ctx.Query("member_id") // уникальный идентификатор портала, на котором происходит авторизация
|
|||
|
server_domain := ctx.Query("server_domain") // домен сервера авторизации
|
|||
|
|
|||
|
if state == "" {
|
|||
|
return ctx.Status(fiber.StatusBadRequest).SendString("State don't be empty")
|
|||
|
}
|
|||
|
|
|||
|
accountID, _, err := tools.DeserializeProtobufMessage(state)
|
|||
|
if err != nil {
|
|||
|
c.logger.Error("error Deserialize Protobuf Message", zap.Error(err))
|
|||
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|||
|
}
|
|||
|
|
|||
|
if accountID == "" || code == "" || referer == "" {
|
|||
|
c.logger.Error("error required fields do not be nil", zap.Error(err))
|
|||
|
return ctx.Status(fiber.StatusBadRequest).SendString("nil required fields")
|
|||
|
}
|
|||
|
|
|||
|
req := service.ParamsWebhookCreate{
|
|||
|
Code: code,
|
|||
|
Referer: referer,
|
|||
|
AccountID: accountID,
|
|||
|
FromWidget: fromWidget,
|
|||
|
Platform: platform,
|
|||
|
}
|
|||
|
|
|||
|
err = c.service.WebhookCreate(ctx.Context(), req)
|
|||
|
if err != nil {
|
|||
|
c.logger.Error("error create webhook", zap.Error(err))
|
|||
|
return ctx.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("Internal Server Error: %v", err.Error()))
|
|||
|
}
|
|||
|
|
|||
|
return ctx.Redirect(c.redirectURL)
|
|||
|
}
|
|||
|
|
|||
|
//// todo проверить надо
|
|||
|
//func (c *WebhookController) WebhookDelete(ctx *fiber.Ctx) error {
|
|||
|
// clientUUID := ctx.Query("client_uuid")
|
|||
|
// signature := ctx.Query("signature")
|
|||
|
// amoIDStr := ctx.Query("account_id")
|
|||
|
//
|
|||
|
// fmt.Println(clientUUID)
|
|||
|
// fmt.Println(signature)
|
|||
|
// fmt.Println(amoIDStr)
|
|||
|
//
|
|||
|
// if clientUUID == "" || signature == "" || amoIDStr == "" {
|
|||
|
// return ctx.Status(fiber.StatusBadRequest).SendString("some nil values")
|
|||
|
// }
|
|||
|
//
|
|||
|
// amoID, err := strconv.Atoi(amoIDStr)
|
|||
|
// if err != nil {
|
|||
|
// return ctx.Status(fiber.StatusBadRequest).SendString("invalid account_id type")
|
|||
|
// }
|
|||
|
//
|
|||
|
// if !c.verify.CheckIntegrationID(clientUUID) {
|
|||
|
// return ctx.Status(fiber.StatusUnauthorized).SendString("invalid hook signature")
|
|||
|
// }
|
|||
|
//
|
|||
|
// if !c.verify.VerifySignature(clientUUID, signature, amoID) {
|
|||
|
// return ctx.Status(fiber.StatusUnauthorized).SendString("invalid hook signature")
|
|||
|
// }
|
|||
|
//
|
|||
|
// err = c.service.WebhookDelete(ctx.Context(), amoID)
|
|||
|
// if err != nil {
|
|||
|
// return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|||
|
// }
|
|||
|
//
|
|||
|
// return ctx.SendStatus(fiber.StatusOK)
|
|||
|
//}
|