2024-01-16 16:13:06 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.gocasts.ir/ebhomengo/niki/config"
|
2024-01-25 11:43:39 +00:00
|
|
|
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
|
2024-01-16 16:13:06 +00:00
|
|
|
mw "github.com/labstack/echo-jwt/v4"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2024-08-01 10:20:18 +00:00
|
|
|
func Auth(service authservice.Service) echo.MiddlewareFunc {
|
2024-01-16 16:13:06 +00:00
|
|
|
return mw.WithConfig(mw.Config{
|
|
|
|
ContextKey: config.AuthMiddlewareContextKey,
|
2024-08-01 10:20:18 +00:00
|
|
|
SigningKey: []byte(service.Config.SignKey),
|
2024-01-16 16:13:06 +00:00
|
|
|
// TODO - as sign method string to config
|
|
|
|
SigningMethod: "HS256",
|
|
|
|
ParseTokenFunc: func(c echo.Context, auth string) (interface{}, error) {
|
|
|
|
claims, err := service.ParseToken(auth)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return claims, nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|