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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Auth(service authservice.Service, cfg authservice.Config) echo.MiddlewareFunc {
|
|
|
|
return mw.WithConfig(mw.Config{
|
|
|
|
ContextKey: config.AuthMiddlewareContextKey,
|
|
|
|
SigningKey: []byte(cfg.SignKey),
|
|
|
|
// 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
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|