diff --git a/.gitignore b/.gitignore index 2b70277..da9801a 100644 --- a/.gitignore +++ b/.gitignore @@ -159,3 +159,4 @@ fabric.properties .ionide # End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,goland,go +main diff --git a/internal/controllers/webhook.go b/internal/controllers/webhook.go index 2778ffb..397414c 100644 --- a/internal/controllers/webhook.go +++ b/internal/controllers/webhook.go @@ -23,13 +23,13 @@ func (c *WebhookController) WebhookCreate(ctx *fiber.Ctx) error { return ctx.Status(http.StatusForbidden).SendString("Access denied") } - accountID, err := tools.DeserializeProtobufMessage(state) + accountID, redirectURL, 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 == nil { + if accountID == "" { c.logger.Error("error account id do not be nil", zap.Error(err)) return ctx.Status(fiber.StatusBadRequest).SendString("nil account id") } @@ -37,7 +37,7 @@ func (c *WebhookController) WebhookCreate(ctx *fiber.Ctx) error { req := service.ParamsWebhookCreate{ Code: code, Referer: referer, - AccountID: *accountID, + AccountID: accountID, FromWidget: fromWidget, Platform: platform, } @@ -48,7 +48,7 @@ func (c *WebhookController) WebhookCreate(ctx *fiber.Ctx) error { return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error") } - return ctx.SendStatus(fiber.StatusOK) + return ctx.Redirect(redirectURL) } // todo проверить надо diff --git a/internal/tools/proto.go b/internal/tools/proto.go index b748776..dad11c1 100644 --- a/internal/tools/proto.go +++ b/internal/tools/proto.go @@ -5,13 +5,18 @@ import ( "google.golang.org/protobuf/proto" ) -func DeserializeProtobufMessage(protobufMessage string) (*string, error) { +func DeserializeProtobufMessage(protobufMessage string) (string, string, error) { msg := socialauth.Message{} err := proto.Unmarshal([]byte(protobufMessage), &msg) if err != nil { - return nil, err + return "", "", err } - return msg.AccessToken, nil + var accountID string + if msg.AccessToken != nil { + accountID = *msg.AccessToken + } + + return accountID, msg.ReturnURL, nil } diff --git a/main b/main deleted file mode 100755 index e0647f5..0000000 Binary files a/main and /dev/null differ