31 lines
979 B
Go
31 lines
979 B
Go
package mw
|
|
|
|
import (
|
|
"astra-api-gateway/config"
|
|
"github.com/golang-jwt/jwt/v5"
|
|
"github.com/labstack/echo-jwt/v4"
|
|
"github.com/labstack/echo/v4"
|
|
"strings"
|
|
)
|
|
|
|
var JWT_MW = echojwt.WithConfig(echojwt.Config{
|
|
SigningKey: []byte(config.Env.Server.JWTSecret),
|
|
Skipper: func(c echo.Context) bool {
|
|
// Skip authentication for signup and login requests
|
|
if strings.Contains(c.Path(), "auth") || c.Path() == "/api/health" {
|
|
return true
|
|
}
|
|
return false
|
|
},
|
|
SuccessHandler: func(c echo.Context) {
|
|
user := c.Get("user").(*jwt.Token)
|
|
claims := user.Claims.(jwt.MapClaims)
|
|
c.Request().Header.Set("UserId", claims["id"].(string))
|
|
c.Request().Header.Set("UserRole", claims["role"].(string))
|
|
c.Request().Header.Set("UserOrganizationId", claims["position_org_id"].(string))
|
|
c.Request().Header.Set("UserRightMask", claims["position_rm"].(string))
|
|
c.Request().Header.Set("UserPosition", claims["position_name"].(string))
|
|
c.Request().Header.Del("Authorization")
|
|
},
|
|
})
|