|
|
@@ -199,13 +199,16 @@ func HandleAuth(ctx context.Context, req *protocol.Message, token string, authEx
|
|
|
path := "/" + req.ServicePath + "/" + req.ServiceMethod
|
|
|
//g.Log().Info("reqPath: ", path)
|
|
|
//g.Log().Info("token: ", token)
|
|
|
- req.Metadata["authExclude"] = "true"
|
|
|
|
|
|
if authPath(path, authExcludePaths) {
|
|
|
req.Metadata["authExclude"] = "false"
|
|
|
-
|
|
|
- //rsp := validToken(token)
|
|
|
- rsp := gtoken.GFToken.ValidToken(token)
|
|
|
+ var rsp gtoken.Resp
|
|
|
+ notAuthSrv := ctx.Value("NotAuthSrv")
|
|
|
+ if notAuthSrv != nil && notAuthSrv.(bool) {
|
|
|
+ rsp = gtoken.GFToken.ValidToken(token)
|
|
|
+ } else {
|
|
|
+ rsp = validToken(token)
|
|
|
+ }
|
|
|
|
|
|
//return errors.New("InvalidToken")
|
|
|
if rsp.Code != 0 {
|
|
|
@@ -259,23 +262,27 @@ func authPath(urlPath string, authExcludePaths []string) bool {
|
|
|
}
|
|
|
|
|
|
// 验证token
|
|
|
-func validToken(token string) auth.Response {
|
|
|
- rsp := &auth.Response{}
|
|
|
+func validToken(token string) gtoken.Resp {
|
|
|
+ grsp := gtoken.Resp{}
|
|
|
if token == "" {
|
|
|
- rsp.Code = 401
|
|
|
- rsp.Msg = "valid token empty"
|
|
|
- return *rsp
|
|
|
+ grsp.Code = 401
|
|
|
+ grsp.Msg = "valid token empty"
|
|
|
+ return grsp
|
|
|
}
|
|
|
|
|
|
authService := InitMicroSrvClient("Auth", "micro_srv.auth")
|
|
|
defer authService.Close()
|
|
|
+ rsp := &auth.Response{}
|
|
|
err := authService.Call(context.TODO(), "ValidToken", token, rsp)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
- rsp.Code = 401
|
|
|
- return *rsp
|
|
|
+ grsp.Code = 401
|
|
|
+ return grsp
|
|
|
}
|
|
|
- return *rsp
|
|
|
+ grsp.Code = int(rsp.Code)
|
|
|
+ grsp.Msg = rsp.Msg
|
|
|
+ grsp.Data = rsp.Data
|
|
|
+ return grsp
|
|
|
}
|
|
|
|
|
|
// IsAuthExclude 是否进行auth验证
|