Browse Source

update auth

master
DengBiao 2 years ago
parent
commit
3af7f2547c
3 changed files with 14 additions and 5 deletions
  1. +1
    -0
      internal/business/domain/user/service/auth.go
  2. +10
    -3
      pkg/interceptor/interceptor.go
  3. +3
    -2
      test/tcp_conn/main.go

+ 1
- 0
internal/business/domain/user/service/auth.go View File

@@ -123,5 +123,6 @@ func (*authService) AuthMaster(ctx context.Context, masterId string) error {
if packageExpireTime < time.Now().Unix() {
return gerrors.ErrMasterUnauthorized
}

return nil
}

+ 10
- 3
pkg/interceptor/interceptor.go View File

@@ -25,15 +25,22 @@ func NewInterceptor(name string, urlWhitelist map[string]int) grpc.UnaryServerIn
logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req),
zap.Any("resp", resp), zap.Error(err))

s, _ := status.FromError(err)
if s.Code() != 0 && s.Code() < 1000 {
md, _ := metadata.FromIncomingContext(ctx)
logger.Logger.Error(name, zap.String("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req),
zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(s)))
}

resp, err = handleWithAuth(ctx, req, info, handler, urlWhitelist)
logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req),
zap.Any("resp", resp), zap.Error(err))

s, _ := status.FromError(err)
if s.Code() != 0 && s.Code() < 1000 {
ss, _ := status.FromError(err)
if ss.Code() != 0 && ss.Code() < 1000 {
md, _ := metadata.FromIncomingContext(ctx)
logger.Logger.Error(name, zap.String("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req),
zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(s)))
zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(ss)))
}
return
}


+ 3
- 2
test/tcp_conn/main.go View File

@@ -67,7 +67,8 @@ func (c *TcpClient) Output(pt pb.PackageType, requestId int64, message proto.Mes
func (c *TcpClient) Start() {

//connect, err := net.Dial("tcp", "111.229.238.28:8080")
connect, err := net.Dial("tcp", "im-tcp-connect.izhyin.com:8001")
//connect, err := net.Dial("tcp", "im-tcp-connect.izhyin.com:8001")
connect, err := net.Dial("tcp", "im-tcp-connect.zhiyingos.com:8001")
if err != nil {
log.Println(err)
return
@@ -87,7 +88,7 @@ func (c *TcpClient) SignIn() {
signIn := pb.SignInInput{
UserId: c.UserId,
DeviceId: c.DeviceId,
Token: "ZDNMWLHJYMDYHKBWESEVHQWXFPCLAGMIUWFOHWNI",
Token: "DIGHPXERETPBZWVFSOCBUTMUFONSLDUZZBADYLLR",
}
c.Output(pb.PackageType_PT_SIGN_IN, time.Now().UnixNano(), &signIn)
}


Loading…
Cancel
Save