...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"github.com/linmadan/egglib-go/web/beego/filters"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api/authlib"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/port/beego/controllers"
|
|
|
"net/http"
|
|
|
"os"
|
...
|
...
|
@@ -76,6 +77,9 @@ func CreateRequestLogFilter(console bool) func(ctx *context.Context) { |
|
|
}
|
|
|
|
|
|
func JwtFilter() func(ctx *context.Context) {
|
|
|
authLib := authlib.NewApiAuthLib(constant.AUTH_SERVER_HOST)
|
|
|
authLib.BaseServiceGateway.ConnectTimeout = 200 * time.Millisecond
|
|
|
authLib.BaseServiceGateway.ReadWriteTimeout = 200 * time.Millisecond
|
|
|
return func(ctx *context.Context) {
|
|
|
//token := ctx.Request.Header.Get("Authorization")
|
|
|
token := ctx.Request.Header.Get("x-mmm-accesstoken")
|
...
|
...
|
@@ -85,17 +89,35 @@ func JwtFilter() func(ctx *context.Context) { |
|
|
err := userToken.ParseToken(token)
|
|
|
if err != nil {
|
|
|
ctx.Output.SetStatus(http.StatusOK)
|
|
|
ctx.Output.JSON(map[string]interface{}{
|
|
|
"msg": "token 过期或无效,需刷新令牌",
|
|
|
"code": 901,
|
|
|
"data": struct{}{},
|
|
|
}, false, false)
|
|
|
ctx.Output.JSON(WithCodeMsgResponse(domain.InvalidRefreshToken), false, false)
|
|
|
return
|
|
|
}
|
|
|
if userToken.UserId > 0 && userToken.CompanyId > 0 {
|
|
|
loginCheckResponse, _ := authLib.LoginCheck(authlib.RequestLoginCheck{Token: token})
|
|
|
if loginCheckResponse != nil && loginCheckResponse.Code == 901 {
|
|
|
ctx.Output.SetStatus(http.StatusOK)
|
|
|
ctx.Output.JSON(WithCodeMsgResponse(domain.InvalidRefreshToken), false, false)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
ctx.Input.SetData("UserToken", userToken)
|
|
|
ctx.Input.SetData("Accesstoken", token)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func WithCodeMsgResponse(code int) map[string]interface{} {
|
|
|
msg := "token 过期或无效,需刷新令牌"
|
|
|
if codeMsg, ok := domain.CodeMsg[code]; ok {
|
|
|
msg = codeMsg
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"msg": msg,
|
|
|
"code": code,
|
|
|
"data": struct{}{},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func RequestCostBefore() func(ctx *context.Context) {
|
|
|
return func(ctx *context.Context) {
|
|
|
ctx.Input.SetData("cost-begin", time.Now().UnixMilli())
|
...
|
...
|
|