feat 废弃jwt 、 学识分
This commit is contained in:
@@ -2,9 +2,10 @@ package http_gateway
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/config"
|
||||
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
@@ -63,17 +64,18 @@ func authJwt() gin.HandlerFunc {
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
claims, err := utils.ParseToken(token, config.Get().Auth.Secret)
|
||||
if err != nil {
|
||||
|
||||
usn, _ := redis.GetClient().HGet(c, global.KeyGatewayAccessToken+token, (&utils.UserSession{}).GetUsnKey()).Int64()
|
||||
if usn == 0 {
|
||||
http_resp.JsonUnauthorized(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 这里将Header写到请求中,grpc-gateway框架会读取然后传给grpc服务
|
||||
c.Request.Header.Set("X-Usn", utils.Int64ToString(claims.USN))
|
||||
c.Request.Header.Set("X-Usn", utils.Int64ToString(usn))
|
||||
// 这里写到上下文中,打日志
|
||||
c.Set("usn", claims.USN)
|
||||
c.Set("usn", usn)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user