From 47001719099f412f2551b727007a7ee78af1c5d4 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Thu, 21 Sep 2023 19:58:16 +0800 Subject: [PATCH] add client param for auth plugin --- auth/example/grpc/main.go | 2 +- auth/example/http/main.go | 3 ++- auth/proto/auth.pb.go | 36 +++++++++++++++++++++++------------- auth/proto/auth.proto | 1 + 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/auth/example/grpc/main.go b/auth/example/grpc/main.go index bc513b5..de11fb3 100644 --- a/auth/example/grpc/main.go +++ b/auth/example/grpc/main.go @@ -33,7 +33,7 @@ func (s *server) Authenticate(ctx context.Context, in *proto.AuthenticateRequest reply.Ok = true reply.Id = "gost" } - log.Printf("auth: %s, %s, %v", in.GetUsername(), in.GetPassword(), reply.Ok) + log.Printf("auth: %s %s, %s, %v", in.Client, in.GetUsername(), in.GetPassword(), reply.Ok) return reply, nil } diff --git a/auth/example/http/main.go b/auth/example/http/main.go index 01f2315..a70ea43 100644 --- a/auth/example/http/main.go +++ b/auth/example/http/main.go @@ -16,6 +16,7 @@ var ( type autherRequest struct { Username string `json:"username"` Password string `json:"password"` + Client string `json:"client"` } type autherResponse struct { @@ -45,7 +46,7 @@ func main() { resp.ID = "gost" } - log.Printf("auth: %s, %s, %v", rb.Username, rb.Password, resp.OK) + log.Printf("auth: %s %s, %s, %v", rb.Client, rb.Username, rb.Password, resp.OK) json.NewEncoder(w).Encode(resp) }) diff --git a/auth/proto/auth.pb.go b/auth/proto/auth.pb.go index aed19dc..ca85f22 100644 --- a/auth/proto/auth.pb.go +++ b/auth/proto/auth.pb.go @@ -31,6 +31,7 @@ type AuthenticateRequest struct { Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` + Client string `protobuf:"bytes,3,opt,name=client,proto3" json:"client,omitempty"` } func (x *AuthenticateRequest) Reset() { @@ -79,6 +80,13 @@ func (x *AuthenticateRequest) GetPassword() string { return "" } +func (x *AuthenticateRequest) GetClient() string { + if x != nil { + return x.Client + } + return "" +} + type AuthenticateReply struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -138,23 +146,25 @@ var File_auth_proto protoreflect.FileDescriptor var file_auth_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0x4d, 0x0a, 0x13, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, + 0x6f, 0x74, 0x6f, 0x22, 0x65, 0x0a, 0x13, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, - 0x72, 0x64, 0x22, 0x33, 0x0a, 0x11, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, - 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x32, 0x55, 0x0a, 0x0d, 0x41, 0x75, 0x74, 0x68, 0x65, - 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x44, 0x0a, 0x0c, 0x41, 0x75, 0x74, 0x68, - 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74, - 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x26, - 0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, - 0x67, 0x6f, 0x73, 0x74, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x61, 0x75, 0x74, 0x68, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x22, 0x33, 0x0a, 0x11, 0x41, 0x75, + 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, + 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x32, + 0x55, 0x0a, 0x0d, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x6f, 0x72, + 0x12, 0x44, 0x0a, 0x0c, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, + 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, + 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, + 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x26, 0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x67, 0x6f, 0x73, 0x74, 0x2f, 0x70, 0x6c, 0x75, + 0x67, 0x69, 0x6e, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/auth/proto/auth.proto b/auth/proto/auth.proto index e3e5654..f9a61c6 100644 --- a/auth/proto/auth.proto +++ b/auth/proto/auth.proto @@ -9,6 +9,7 @@ option go_package = "github.com/go-gost/plugin/auth/proto"; message AuthenticateRequest { string username = 1; string password = 2; + string client = 3; } message AuthenticateReply {