30 lines
1010 B
Go
30 lines
1010 B
Go
package controllers
|
|
|
|
import (
|
|
"git.secnex.io/secnex/oauth2-api/services"
|
|
"github.com/go-playground/validator/v10"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type AuthorizeRequest struct {
|
|
ClientID string `json:"client_id" validate:"required"`
|
|
RedirectURI string `json:"redirect_uri" validate:"required"`
|
|
ResponseType string `json:"response_type" validate:"required"`
|
|
Scope string `json:"scope" validate:"required"`
|
|
State string `json:"state" validate:"required"`
|
|
}
|
|
|
|
func AuthorizeController(c *fiber.Ctx) error {
|
|
var request AuthorizeRequest
|
|
if err := c.BodyParser(&request); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": err.Error()})
|
|
}
|
|
|
|
if err := validator.New().Struct(request); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": err.Error()})
|
|
}
|
|
|
|
response := services.Authorize(c.Locals("user").(string), request.ClientID, request.RedirectURI, request.ResponseType, request.Scope, request.State)
|
|
return response.Send(c)
|
|
}
|