forked from ebhomengo/niki
1
0
Fork 0
niki/delivery/http_server/middleware/auth.go

26 lines
659 B
Go
Raw Normal View History

package middleware
import (
"git.gocasts.ir/ebhomengo/niki/config"
authservice "git.gocasts.ir/ebhomengo/niki/service/auth"
mw "github.com/labstack/echo-jwt/v4"
"github.com/labstack/echo/v4"
)
func Auth(service authservice.Service) echo.MiddlewareFunc {
return mw.WithConfig(mw.Config{
ContextKey: config.AuthMiddlewareContextKey,
SigningKey: []byte(service.Config.SignKey),
// TODO - as sign method string to config
SigningMethod: "HS256",
ParseTokenFunc: func(c echo.Context, auth string) (interface{}, error) {
claims, err := service.ParseBearerToken(auth)
if err != nil {
return nil, err
}
return claims, nil
},
})
}