(c *fiber.Ctx)
| 66 | } |
| 67 | |
| 68 | func GitlabFetchToken(c *fiber.Ctx) error { |
| 69 | var body models.Token |
| 70 | if err := c.BodyParser(&body); err != nil { |
| 71 | return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ |
| 72 | "message": err.Error(), |
| 73 | }) |
| 74 | } |
| 75 | |
| 76 | _, errors := govalidator.ValidateStruct(body) |
| 77 | if errors != nil { |
| 78 | return c.Status(fiber.StatusUnprocessableEntity).JSON(errors) |
| 79 | } |
| 80 | |
| 81 | reqBody := url.Values{} |
| 82 | |
| 83 | verifier := verifiers[fmt.Sprintf("%v", c.Locals("identifier"))] |
| 84 | reqBody.Set("client_id", api.Http.Gitlab.AppId) |
| 85 | reqBody.Set("client_secret", api.Http.Gitlab.SecretKey) |
| 86 | reqBody.Set("code", body.Code) |
| 87 | reqBody.Set("grant_type", "authorization_code") |
| 88 | reqBody.Set("redirect_uri", api.Http.Gitlab.RedirectUri) |
| 89 | reqBody.Set("code_verifier", verifier.Verifier) |
| 90 | |
| 91 | resp, err := http.Post(fmt.Sprintf("https://%s/oauth/token", api.Http.Gitlab.Domain), "application/x-www-form-urlencoded", strings.NewReader(reqBody.Encode())) |
| 92 | if err != nil { |
| 93 | return c.JSON(err) |
| 94 | } |
| 95 | resBody, err := io.ReadAll(resp.Body) |
| 96 | |
| 97 | if err != nil { |
| 98 | return c.JSON(err) |
| 99 | } |
| 100 | |
| 101 | var response map[string]interface{} |
| 102 | err = json.Unmarshal(resBody, &response) |
| 103 | if err != nil { |
| 104 | return c.Status(http.StatusInternalServerError).JSON(fiber.Map{ |
| 105 | "error": err.Error(), |
| 106 | }) |
| 107 | } |
| 108 | |
| 109 | return c.JSON(response) |
| 110 | } |
| 111 | |
| 112 | func GitlabRefreshToken(c *fiber.Ctx) error { |
| 113 | var body models.Token |
nothing calls this directly
no outgoing calls
no test coverage detected