This commit is contained in:
Lizandro Guarnizo
2025-04-18 07:38:32 -05:00
parent 462eb0d42c
commit 79d6cca94d
23 changed files with 821 additions and 73 deletions
+23 -8
View File
@@ -261,12 +261,27 @@ func AuthAdmin(c *fiber.Ctx) error {
}
func AuthApi() func(*fiber.Ctx) error {
return Authenticate(AuthConfig{
SigningKey: []byte(app.Http.Token.ApiJwtSecret),
TokenLookup: "header:Verify-Rest-Token",
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
auth.Logout(ctx)
return ctx.Status(401).JSON("Invalid Attempt")
},
})
return func(c *fiber.Ctx) error {
// Excluir rutas públicas
if c.Path() == "/api/v1/oauth/token" {
return c.Next()
}
// Obtener el token de la cookie "Verify-Rest-Token"
token := c.Cookies("Verify-Rest-Token")
if token == "" {
// Si no hay token, regresar un error
return c.Status(401).JSON("Token not found")
}
// Continuar con la verificación JWT para otras rutas
return Authenticate(AuthConfig{
SigningKey: []byte(app.Http.Token.ApiJwtSecret),
TokenLookup: "cookie:Verify-Rest-Token", // Ahora se busca en la cookie
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
auth.Logout(ctx)
return ctx.Status(401).JSON("Invalid Attempt")
},
})(c)
}
}