From 551efbf89c614a5f951b32ca167d72e0fa724c50 Mon Sep 17 00:00:00 2001 From: lbzs <627062293@qq.com> Date: Thu, 21 Apr 2022 22:41:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0OTP=E5=8F=8C=E5=9B=A0?= =?UTF-8?q?=E7=B4=A0=E8=AE=A4=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/all/grpc.go | 1 + apps/all/http.go | 1 + apps/otp/app.go | 5 + apps/otp/http/http.go | 38 +++ apps/otp/http/otp.go | 63 +++++ apps/otp/impl/impl.go | 46 ++++ apps/otp/impl/otp.go | 105 ++++++++ apps/otp/impl/query.go | 41 +++ apps/otp/otp.pb.go | 261 ++++++++++++++++++ apps/otp/otp_enum.pb.go | 55 ++++ apps/otp/otp_ext.go | 104 ++++++++ apps/otp/pb/otp.proto | 31 +++ apps/otp/pb/request.proto | 50 ++++ apps/otp/pb/service.proto | 14 + apps/otp/request.pb.go | 497 +++++++++++++++++++++++++++++++++++ apps/otp/request_ext.go | 68 +++++ apps/otp/service.pb.go | 109 ++++++++ apps/otp/service_grpc.pb.go | 213 +++++++++++++++ apps/token/issuer/issuer.go | 25 ++ apps/token/pb/request.proto | 1 + apps/token/pb/token.proto | 1 + apps/token/request.ext.go | 4 + apps/token/request.pb.go | 127 ++++----- apps/token/token.pb.go | 54 ++-- apps/user/impl/impl.go | 3 + apps/user/impl/user.go | 31 ++- apps/user/pb/request.proto | 19 +- apps/user/pb/service.proto | 4 +- apps/user/pb/user.proto | 4 + apps/user/request.pb.go | 373 ++++++++++++++++---------- apps/user/request_ext.go | 12 + apps/user/service.pb.go | 50 ++-- apps/user/service_grpc.pb.go | 38 +++ apps/user/user.pb.go | 178 +++++++------ apps/user/user_ext.go | 4 + 35 files changed, 2309 insertions(+), 321 deletions(-) create mode 100644 apps/otp/app.go create mode 100644 apps/otp/http/http.go create mode 100644 apps/otp/http/otp.go create mode 100644 apps/otp/impl/impl.go create mode 100644 apps/otp/impl/otp.go create mode 100644 apps/otp/impl/query.go create mode 100644 apps/otp/otp.pb.go create mode 100644 apps/otp/otp_enum.pb.go create mode 100644 apps/otp/otp_ext.go create mode 100644 apps/otp/pb/otp.proto create mode 100644 apps/otp/pb/request.proto create mode 100644 apps/otp/pb/service.proto create mode 100644 apps/otp/request.pb.go create mode 100644 apps/otp/request_ext.go create mode 100644 apps/otp/service.pb.go create mode 100644 apps/otp/service_grpc.pb.go diff --git a/apps/all/grpc.go b/apps/all/grpc.go index a588b7a6..a412f7ed 100644 --- a/apps/all/grpc.go +++ b/apps/all/grpc.go @@ -8,6 +8,7 @@ import ( _ "github.com/infraboard/keyauth/apps/mconf/impl" _ "github.com/infraboard/keyauth/apps/micro/impl" _ "github.com/infraboard/keyauth/apps/namespace/impl" + _ "github.com/infraboard/keyauth/apps/otp/impl" _ "github.com/infraboard/keyauth/apps/permission/impl" _ "github.com/infraboard/keyauth/apps/policy/impl" _ "github.com/infraboard/keyauth/apps/role/impl" diff --git a/apps/all/http.go b/apps/all/http.go index 89c07b73..2da3706e 100644 --- a/apps/all/http.go +++ b/apps/all/http.go @@ -10,6 +10,7 @@ import ( _ "github.com/infraboard/keyauth/apps/mconf/http" _ "github.com/infraboard/keyauth/apps/micro/http" _ "github.com/infraboard/keyauth/apps/namespace/http" + _ "github.com/infraboard/keyauth/apps/otp/http" _ "github.com/infraboard/keyauth/apps/permission/http" _ "github.com/infraboard/keyauth/apps/policy/http" _ "github.com/infraboard/keyauth/apps/provider/http" diff --git a/apps/otp/app.go b/apps/otp/app.go new file mode 100644 index 00000000..d5747b2e --- /dev/null +++ b/apps/otp/app.go @@ -0,0 +1,5 @@ +package otp + +const ( + AppName = "OTP" +) diff --git a/apps/otp/http/http.go b/apps/otp/http/http.go new file mode 100644 index 00000000..57fee6e8 --- /dev/null +++ b/apps/otp/http/http.go @@ -0,0 +1,38 @@ +package http + +import ( + "github.com/infraboard/keyauth/apps/otp" + "github.com/infraboard/mcube/app" + "github.com/infraboard/mcube/http/router" +) + +var ( + api = &handler{} +) + +type handler struct { + service otp.ServiceServer +} + +// Registry 注册HTTP服务路由 +func (h *handler) Registry(router router.SubRouter) { + + r := router.ResourceRouter("otp") + r.BasePath("otp") + r.Handle("DELETE", "/:account", h.DeleteOTP) + r.Handle("GET", "/:account", h.GetOTP) + r.Handle("POST", "/", h.UpdateOTP) +} + +func (h *handler) Config() error { + h.service = app.GetGrpcApp(otp.AppName).(otp.ServiceServer) + return nil +} + +func (h *handler) Name() string { + return otp.AppName +} + +func init() { + app.RegistryHttpApp(api) +} diff --git a/apps/otp/http/otp.go b/apps/otp/http/otp.go new file mode 100644 index 00000000..20699c68 --- /dev/null +++ b/apps/otp/http/otp.go @@ -0,0 +1,63 @@ +package http + +import ( + "net/http" + + "github.com/infraboard/keyauth/apps/otp" + "github.com/infraboard/mcube/http/context" + "github.com/infraboard/mcube/http/request" + "github.com/infraboard/mcube/http/response" +) + +// enable OTP +func (h *handler) CreateOTP(w http.ResponseWriter, r *http.Request) { + req := otp.NewCreateOTPAuthRequest() + if err := request.GetDataFromRequest(r, req); err != nil { + response.Failed(w, err) + return + } + ins, err := h.service.CreateOTPAuth(r.Context(), req) + if err != nil { + response.Failed(w, err) + return + } + response.Success(w, ins) +} +func (h *handler) GetOTP(w http.ResponseWriter, r *http.Request) { + ctx := context.GetContext(r) + account := ctx.PS.ByName("account") + req := otp.NewDescribeOTPAuthRequestWithName(account) + ins, err := h.service.DescribeOTPAuth(r.Context(), req) + if err != nil { + response.Failed(w, err) + return + } + response.Success(w, ins) +} + +func (h *handler) DeleteOTP(w http.ResponseWriter, r *http.Request) { + ctx := context.GetContext(r) + account := ctx.PS.ByName("account") + req := otp.NewDeleteOTPAuthRequestWithName(account) + ins, err := h.service.DeleteOTPAuth(r.Context(), req) + if err != nil { + response.Failed(w, err) + return + } + response.Success(w, ins) +} + +func (h *handler) UpdateOTP(w http.ResponseWriter, r *http.Request) { + req := otp.NewUpdateOTPStatusRequest() + if err := request.GetDataFromRequest(r, req); err != nil { + response.Failed(w, err) + return + } + + d, err := h.service.UpdateOTPAuthStatus(r.Context(), req) + if err != nil { + response.Failed(w, err) + return + } + response.Success(w, d) +} diff --git a/apps/otp/impl/impl.go b/apps/otp/impl/impl.go new file mode 100644 index 00000000..5a178098 --- /dev/null +++ b/apps/otp/impl/impl.go @@ -0,0 +1,46 @@ +package impl + +import ( + "github.com/infraboard/keyauth/apps/otp" + "github.com/infraboard/keyauth/apps/user" + "github.com/infraboard/keyauth/conf" + "github.com/infraboard/mcube/app" + "github.com/infraboard/mcube/logger" + "github.com/infraboard/mcube/logger/zap" + "go.mongodb.org/mongo-driver/mongo" + "google.golang.org/grpc" +) + +var ( + svr = &service{} +) + +type service struct { + col *mongo.Collection + log logger.Logger + enableCache bool + notifyCachPre string + + user user.ServiceServer + otp.UnimplementedServiceServer +} + +func (s *service) Config() error { + db := conf.C().Mongo.GetDB() + col := db.Collection("otp") + + s.col = col + s.log = zap.L().Named("OTP") + s.user = app.GetGrpcApp(user.AppName).(user.ServiceServer) + return nil +} +func (s *service) Name() string { + return otp.AppName +} +func (s *service) Registry(server *grpc.Server) { + otp.RegisterServiceServer(server, svr) +} + +func init() { + app.RegistryGrpcApp(svr) +} diff --git a/apps/otp/impl/otp.go b/apps/otp/impl/otp.go new file mode 100644 index 00000000..0b8a7bde --- /dev/null +++ b/apps/otp/impl/otp.go @@ -0,0 +1,105 @@ +package impl + +import ( + "context" + "fmt" + + "github.com/infraboard/keyauth/apps/otp" + "github.com/infraboard/keyauth/apps/user" + "github.com/infraboard/mcube/exception" + "go.mongodb.org/mongo-driver/mongo" +) + +func (s *service) CreateOTPAuth(ctx context.Context, req *otp.CreateOTPAuthRequest) (*otp.OTPAuth, error) { + if err := req.Validate(); err != nil { + return nil, exception.NewBadRequest(err.Error()) + } + + ins := otp.NewOTPAuth() + ins.Account = req.Account + ins.GenSecret() + ins.GenOtpCode(ins.Account, ins.SecretKey) + ins.GenQrcodeUrl(ins.Account, ins.SecretKey) + + _, err := s.col.InsertOne(context.Background(), ins) + if err != nil { + return nil, exception.NewInternalServerError("insert document(%s) error, %s", ins, err) + } + return ins, nil +} + +func (s *service) DescribeOTPAuth(ctx context.Context, req *otp.DescribeOTPAuthRequest) (*otp.OTPAuth, error) { + if err := req.Validate(); err != nil { + return nil, exception.NewBadRequest(err.Error()) + } + r := newdescribeOTPAuthRequest(req) + ins := otp.NewOTPAuth() + + if err := s.col.FindOne(context.TODO(), r.FindFilter()).Decode(ins); err != nil { + if err == mongo.ErrNoDocuments { + return nil, exception.NewNotFound("otp for %s not found", req.Account) + } + return nil, exception.NewInternalServerError("find otp %s error, %s", req.Account, err) + } + + return ins, nil +} + +func (s *service) DeleteOTPAuth(ctx context.Context, req *otp.DeleteOTPAuthRequest) (*otp.OTPAuth, error) { + if err := req.Validate(); err != nil { + return nil, exception.NewBadRequest(err.Error()) + } + r := newdeleteOTPAuthRequest(req) + + ins, err := s.DescribeOTPAuth(ctx, otp.NewDescribeOTPAuthRequestWithName(req.Account)) + if err != nil { + return nil, err + } + + _, err = s.col.DeleteOne(context.TODO(), r.FindFilter()) + if err != nil { + return nil, exception.NewInternalServerError("delete document(%s) otp error, %s", r.Account, err) + } + return ins, nil +} + +func (s *service) UpdateOTPAuthStatus(ctx context.Context, req *otp.UpdateOTPStatusRequest) (*otp.OTPAuth, error) { + if err := req.Validate(); err != nil { + return nil, exception.NewBadRequest(err.Error()) + } + + u, err := s.user.DescribeAccount(ctx, user.NewDescriptAccountRequestWithAccount(req.Account)) + if err != nil { + return nil, err + } + + if u.OtpStatus == req.OtpStatus { + return nil, fmt.Errorf("do not need to update OTP status") + } + + u.OtpStatus = req.OtpStatus + updateOTPReq := user.NewUpdateOTPStatusRequest() + updateOTPReq.Account = req.Account + updateOTPReq.OtpStatus = req.OtpStatus + _, err = s.user.UpdateOTPStatus(ctx, updateOTPReq) + if err != nil { + return nil, err + } + + switch req.OtpStatus { + case otp.OTPStatus_DISABLED: + ins, err := s.DeleteOTPAuth(ctx, otp.NewDeleteOTPAuthRequestWithName(req.Account)) + if err != nil { + return nil, err + } + return ins, nil + case otp.OTPStatus_ENABLED: + ins, err := s.CreateOTPAuth(ctx, otp.NewCreateOTPAuthRequestWithName(req.Account)) + if err != nil { + return nil, err + } + return ins, nil + default: + return nil, fmt.Errorf("unknown OTPStatus type") + } +} diff --git a/apps/otp/impl/query.go b/apps/otp/impl/query.go new file mode 100644 index 00000000..b445044e --- /dev/null +++ b/apps/otp/impl/query.go @@ -0,0 +1,41 @@ +package impl + +import ( + "github.com/infraboard/keyauth/apps/otp" + "go.mongodb.org/mongo-driver/bson" +) + +func newdescribeOTPAuthRequest(req *otp.DescribeOTPAuthRequest) *describeOTPAuthRequest { + return &describeOTPAuthRequest{ + DescribeOTPAuthRequest: req, + } +} + +type describeOTPAuthRequest struct { + *otp.DescribeOTPAuthRequest +} + +func (req *describeOTPAuthRequest) FindFilter() bson.M { + filter := bson.M{} + if req.Account != "" { + filter["account"] = req.Account + } + return filter +} +func newdeleteOTPAuthRequest(req *otp.DeleteOTPAuthRequest) *deleteOTPAuthRequest { + return &deleteOTPAuthRequest{ + DeleteOTPAuthRequest: req, + } +} + +type deleteOTPAuthRequest struct { + *otp.DeleteOTPAuthRequest +} + +func (req *deleteOTPAuthRequest) FindFilter() bson.M { + filter := bson.M{} + if req.Account != "" { + filter["account"] = req.Account + } + return filter +} diff --git a/apps/otp/otp.pb.go b/apps/otp/otp.pb.go new file mode 100644 index 00000000..ef3bebb7 --- /dev/null +++ b/apps/otp/otp.pb.go @@ -0,0 +1,261 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.1 +// source: apps/otp/pb/otp.proto + +package otp + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type OTPStatus int32 + +const ( + OTPStatus_UNKNOWN OTPStatus = 0 + OTPStatus_ENABLED OTPStatus = 1 + OTPStatus_DISABLED OTPStatus = 2 +) + +// Enum value maps for OTPStatus. +var ( + OTPStatus_name = map[int32]string{ + 0: "UNKNOWN", + 1: "ENABLED", + 2: "DISABLED", + } + OTPStatus_value = map[string]int32{ + "UNKNOWN": 0, + "ENABLED": 1, + "DISABLED": 2, + } +) + +func (x OTPStatus) Enum() *OTPStatus { + p := new(OTPStatus) + *p = x + return p +} + +func (x OTPStatus) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (OTPStatus) Descriptor() protoreflect.EnumDescriptor { + return file_apps_otp_pb_otp_proto_enumTypes[0].Descriptor() +} + +func (OTPStatus) Type() protoreflect.EnumType { + return &file_apps_otp_pb_otp_proto_enumTypes[0] +} + +func (x OTPStatus) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use OTPStatus.Descriptor instead. +func (OTPStatus) EnumDescriptor() ([]byte, []int) { + return file_apps_otp_pb_otp_proto_rawDescGZIP(), []int{0} +} + +type OTPAuth struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // OTP密钥 + // @gotags: bson:"_id" json:"secret_key" + SecretKey string `protobuf:"bytes,1,opt,name=secret_key,json=secretKey,proto3" json:"secret_key" bson:"_id"` + // OTP过期时间 + // @gotags: bson:"expired_second" json:"expired_second" + ExpiredSecond uint64 `protobuf:"varint,2,opt,name=expired_second,json=expiredSecond,proto3" json:"expired_second" bson:"expired_second"` + // OTP长度 + // @gotags: bson:"digits" json:"digits" + Digits int32 `protobuf:"varint,3,opt,name=digits,proto3" json:"digits" bson:"digits"` + // OTP二维码内容 + // @gotags: bson:"otp_code" json:"otp_code" + OtpCode string `protobuf:"bytes,4,opt,name=otp_code,json=otpCode,proto3" json:"otp_code" bson:"otp_code"` + // OTP二维码图片地址 + // @gotags: bson:"otp_url" json:"otp_url" + OtpUrl string `protobuf:"bytes,5,opt,name=otp_url,json=otpUrl,proto3" json:"otp_url" bson:"otp_url"` + // 用户名 + // @gotags: bson:"account" json:"account" + Account string `protobuf:"bytes,6,opt,name=account,proto3" json:"account" bson:"account"` +} + +func (x *OTPAuth) Reset() { + *x = OTPAuth{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_otp_pb_otp_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OTPAuth) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OTPAuth) ProtoMessage() {} + +func (x *OTPAuth) ProtoReflect() protoreflect.Message { + mi := &file_apps_otp_pb_otp_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OTPAuth.ProtoReflect.Descriptor instead. +func (*OTPAuth) Descriptor() ([]byte, []int) { + return file_apps_otp_pb_otp_proto_rawDescGZIP(), []int{0} +} + +func (x *OTPAuth) GetSecretKey() string { + if x != nil { + return x.SecretKey + } + return "" +} + +func (x *OTPAuth) GetExpiredSecond() uint64 { + if x != nil { + return x.ExpiredSecond + } + return 0 +} + +func (x *OTPAuth) GetDigits() int32 { + if x != nil { + return x.Digits + } + return 0 +} + +func (x *OTPAuth) GetOtpCode() string { + if x != nil { + return x.OtpCode + } + return "" +} + +func (x *OTPAuth) GetOtpUrl() string { + if x != nil { + return x.OtpUrl + } + return "" +} + +func (x *OTPAuth) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +var File_apps_otp_pb_otp_proto protoreflect.FileDescriptor + +var file_apps_otp_pb_otp_proto_rawDesc = []byte{ + 0x0a, 0x15, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x2f, 0x70, 0x62, 0x2f, 0x6f, 0x74, + 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x16, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, + 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x22, + 0xb5, 0x01, 0x0a, 0x07, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x12, 0x1d, 0x0a, 0x0a, 0x73, + 0x65, 0x63, 0x72, 0x65, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x25, 0x0a, 0x0e, 0x65, 0x78, + 0x70, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x0d, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x64, 0x53, 0x65, 0x63, 0x6f, 0x6e, + 0x64, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x69, 0x67, 0x69, 0x74, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x06, 0x64, 0x69, 0x67, 0x69, 0x74, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x74, 0x70, + 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x74, 0x70, + 0x43, 0x6f, 0x64, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x6f, 0x74, 0x70, 0x5f, 0x75, 0x72, 0x6c, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x74, 0x70, 0x55, 0x72, 0x6c, 0x12, 0x18, 0x0a, + 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2a, 0x33, 0x0a, 0x09, 0x4f, 0x54, 0x50, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, + 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x45, 0x4e, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0c, + 0x0a, 0x08, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x02, 0x42, 0x28, 0x5a, 0x26, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, + 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, + 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_apps_otp_pb_otp_proto_rawDescOnce sync.Once + file_apps_otp_pb_otp_proto_rawDescData = file_apps_otp_pb_otp_proto_rawDesc +) + +func file_apps_otp_pb_otp_proto_rawDescGZIP() []byte { + file_apps_otp_pb_otp_proto_rawDescOnce.Do(func() { + file_apps_otp_pb_otp_proto_rawDescData = protoimpl.X.CompressGZIP(file_apps_otp_pb_otp_proto_rawDescData) + }) + return file_apps_otp_pb_otp_proto_rawDescData +} + +var file_apps_otp_pb_otp_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_apps_otp_pb_otp_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_apps_otp_pb_otp_proto_goTypes = []interface{}{ + (OTPStatus)(0), // 0: infraboard.keyauth.otp.OTPStatus + (*OTPAuth)(nil), // 1: infraboard.keyauth.otp.OTPAuth +} +var file_apps_otp_pb_otp_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_apps_otp_pb_otp_proto_init() } +func file_apps_otp_pb_otp_proto_init() { + if File_apps_otp_pb_otp_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_apps_otp_pb_otp_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OTPAuth); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_apps_otp_pb_otp_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_apps_otp_pb_otp_proto_goTypes, + DependencyIndexes: file_apps_otp_pb_otp_proto_depIdxs, + EnumInfos: file_apps_otp_pb_otp_proto_enumTypes, + MessageInfos: file_apps_otp_pb_otp_proto_msgTypes, + }.Build() + File_apps_otp_pb_otp_proto = out.File + file_apps_otp_pb_otp_proto_rawDesc = nil + file_apps_otp_pb_otp_proto_goTypes = nil + file_apps_otp_pb_otp_proto_depIdxs = nil +} diff --git a/apps/otp/otp_enum.pb.go b/apps/otp/otp_enum.pb.go new file mode 100644 index 00000000..12efdbb9 --- /dev/null +++ b/apps/otp/otp_enum.pb.go @@ -0,0 +1,55 @@ +// Code generated by github.com/infraboard/mcube +// DO NOT EDIT + +package otp + +import ( + "bytes" + "fmt" + "strings" +) + +// ParseOTPStatusFromString Parse OTPStatus from string +func ParseOTPStatusFromString(str string) (OTPStatus, error) { + key := strings.Trim(string(str), `"`) + v, ok := OTPStatus_value[strings.ToUpper(key)] + if !ok { + return 0, fmt.Errorf("unknown OTPStatus: %s", str) + } + + return OTPStatus(v), nil +} + +// Equal type compare +func (t OTPStatus) Equal(target OTPStatus) bool { + return t == target +} + +// IsIn todo +func (t OTPStatus) IsIn(targets ...OTPStatus) bool { + for _, target := range targets { + if t.Equal(target) { + return true + } + } + + return false +} + +// MarshalJSON todo +func (t OTPStatus) MarshalJSON() ([]byte, error) { + b := bytes.NewBufferString(`"`) + b.WriteString(strings.ToUpper(t.String())) + b.WriteString(`"`) + return b.Bytes(), nil +} + +// UnmarshalJSON todo +func (t *OTPStatus) UnmarshalJSON(b []byte) error { + ins, err := ParseOTPStatusFromString(string(b)) + if err != nil { + return err + } + *t = ins + return nil +} diff --git a/apps/otp/otp_ext.go b/apps/otp/otp_ext.go new file mode 100644 index 00000000..a4914cb7 --- /dev/null +++ b/apps/otp/otp_ext.go @@ -0,0 +1,104 @@ +package otp + +import ( + "bytes" + "crypto/hmac" + "crypto/sha1" + "encoding/base32" + "encoding/binary" + "fmt" + "net/url" + "strings" + "time" +) + +const ( + DefaultExpiredSecond = 30 + DefaultDigits = 6 +) + +func NewOTPAuth() *OTPAuth { + return &OTPAuth{ + ExpiredSecond: DefaultExpiredSecond, + Digits: DefaultDigits, + } +} + +func (g *OTPAuth) un() int64 { + return time.Now().UnixNano() / 1000 / 30 +} + +func (g *OTPAuth) hmacSha1(key, data []byte) []byte { + h := hmac.New(sha1.New, key) + if total := len(data); total > 0 { + h.Write(data) + } + return h.Sum(nil) +} + +func (g *OTPAuth) base32encode(src []byte) string { + return base32.StdEncoding.EncodeToString(src) +} + +func (g *OTPAuth) base32decode(s string) ([]byte, error) { + return base32.StdEncoding.DecodeString(s) +} + +func (g *OTPAuth) toBytes(value int64) []byte { + var result []byte + mask := int64(0xFF) + shifts := [8]uint16{56, 48, 40, 32, 24, 16, 8, 0} + for _, shift := range shifts { + result = append(result, byte((value>>shift)&mask)) + } + return result +} + +func (g *OTPAuth) toUint32(bts []byte) uint32 { + return (uint32(bts[0]) << 24) + (uint32(bts[1]) << 16) + + (uint32(bts[2]) << 8) + uint32(bts[3]) +} + +func (g *OTPAuth) oneTimePassword(key []byte, data []byte) uint32 { + hash := g.hmacSha1(key, data) + offset := hash[len(hash)-1] & 0x0F + hashParts := hash[offset : offset+4] + hashParts[0] = hashParts[0] & 0x7F + number := g.toUint32(hashParts) + return number % 1000000 +} + +// 获取秘钥 +func (g *OTPAuth) GenSecret() { + var buf bytes.Buffer + binary.Write(&buf, binary.BigEndian, g.un()) + secret := strings.ToUpper(g.base32encode(g.hmacSha1(buf.Bytes(), nil))) + g.SecretKey = secret +} + +// 获取动态码 +func (g *OTPAuth) GenCode(secret string) (string, error) { + secretUpper := strings.ToUpper(secret) + secretKey, err := g.base32decode(secretUpper) + if err != nil { + return "", err + } + number := g.oneTimePassword(secretKey, g.toBytes(time.Now().Unix()/30)) + return fmt.Sprintf("%06d", number), nil +} + +// 获取动态码二维码内容 +func (g *OTPAuth) GenOtpCode(user, secret string) { + otpcode := fmt.Sprintf("otpauth://totp/%s?secret=%s", user, secret) + g.OtpCode = otpcode +} + +// 获取动态码二维码图片地址,这里是第三方二维码api +func (g *OTPAuth) GenQrcodeUrl(user, secret string) { + width := "200" + height := "200" + data := url.Values{} + data.Set("data", g.OtpCode) + codeurl := "https://api.qrserver.com/v1/create-qr-code/?" + data.Encode() + "&size=" + width + "x" + height + "&ecc=M" + g.OtpUrl = codeurl +} diff --git a/apps/otp/pb/otp.proto b/apps/otp/pb/otp.proto new file mode 100644 index 00000000..d4dfc805 --- /dev/null +++ b/apps/otp/pb/otp.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; + +package infraboard.keyauth.otp; +option go_package = "github.com/infraboard/keyauth/apps/otp"; + +message OTPAuth{ + // OTP密钥 + // @gotags: bson:"_id" json:"secret_key" + string secret_key = 1; + // OTP过期时间 + // @gotags: bson:"expired_second" json:"expired_second" + uint64 expired_second = 2; + // OTP长度 + // @gotags: bson:"digits" json:"digits" + int32 digits = 3; + // OTP二维码内容 + // @gotags: bson:"otp_code" json:"otp_code" + string otp_code = 4; + // OTP二维码图片地址 + // @gotags: bson:"otp_url" json:"otp_url" + string otp_url = 5; + // 用户名 + // @gotags: bson:"account" json:"account" + string account = 6; +} + +enum OTPStatus { + UNKNOWN = 0; + ENABLED = 1; + DISABLED = 2; +} \ No newline at end of file diff --git a/apps/otp/pb/request.proto b/apps/otp/pb/request.proto new file mode 100644 index 00000000..27f4e1fe --- /dev/null +++ b/apps/otp/pb/request.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; + +package infraboard.keyauth.otp; +option go_package = "github.com/infraboard/keyauth/apps/otp"; + +import "apps/otp/pb/otp.proto"; + +// CreateOTPAuthRequest 创建OTP请求 +message CreateOTPAuthRequest { + // 关联用户 + // @gotags: json:"account" validate:"required" + string account = 1; +} + +// DescribeOTPAuthRequest 查询OTP请求 +message DescribeOTPAuthRequest { + // 关联用户 + // @gotags: json:"account" validate:"required" + string account = 1; +} + +// DeleteOTPAuthRequest 删除OTP请求 +message DeleteOTPAuthRequest { + // 关联用户 + // @gotags: json:"account" validate:"required" + string account = 1; +} + +// 启用OTP +message EnableOTPAuthRequest { + // 关联用户 + // @gotags: json:"account" validate:"required" + string account = 1; +} + +// 禁用OTP +message DisableOTPAuthRequest { + // 关联用户 + // @gotags: json:"account" validate:"required" + string account = 1; +} + +message UpdateOTPStatusRequest { + // 关联用户 + // @gotags: json:"account" validate:"required" + string account = 1; + // OTP是否开启 + // @gotags: json:"otp_status" validate:"required" + otp.OTPStatus otp_status = 2; +} \ No newline at end of file diff --git a/apps/otp/pb/service.proto b/apps/otp/pb/service.proto new file mode 100644 index 00000000..59c8fa05 --- /dev/null +++ b/apps/otp/pb/service.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package infraboard.keyauth.otp; +option go_package = "github.com/infraboard/keyauth/apps/otp"; + +import "apps/otp/pb/request.proto"; +import "apps/otp/pb/otp.proto"; + +service Service { + rpc CreateOTPAuth(CreateOTPAuthRequest) returns(OTPAuth); + rpc DescribeOTPAuth(DescribeOTPAuthRequest) returns(OTPAuth); + rpc DeleteOTPAuth(DeleteOTPAuthRequest) returns(OTPAuth); + rpc UpdateOTPAuthStatus(UpdateOTPStatusRequest) returns(OTPAuth); +} \ No newline at end of file diff --git a/apps/otp/request.pb.go b/apps/otp/request.pb.go new file mode 100644 index 00000000..ac0bc0c8 --- /dev/null +++ b/apps/otp/request.pb.go @@ -0,0 +1,497 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.1 +// source: apps/otp/pb/request.proto + +package otp + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// CreateOTPAuthRequest 创建OTP请求 +type CreateOTPAuthRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // 关联用户 + // @gotags: json:"account" validate:"required" + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account" validate:"required"` +} + +func (x *CreateOTPAuthRequest) Reset() { + *x = CreateOTPAuthRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_otp_pb_request_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateOTPAuthRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateOTPAuthRequest) ProtoMessage() {} + +func (x *CreateOTPAuthRequest) ProtoReflect() protoreflect.Message { + mi := &file_apps_otp_pb_request_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateOTPAuthRequest.ProtoReflect.Descriptor instead. +func (*CreateOTPAuthRequest) Descriptor() ([]byte, []int) { + return file_apps_otp_pb_request_proto_rawDescGZIP(), []int{0} +} + +func (x *CreateOTPAuthRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +// DescribeOTPAuthRequest 查询OTP请求 +type DescribeOTPAuthRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // 关联用户 + // @gotags: json:"account" validate:"required" + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account" validate:"required"` +} + +func (x *DescribeOTPAuthRequest) Reset() { + *x = DescribeOTPAuthRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_otp_pb_request_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DescribeOTPAuthRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DescribeOTPAuthRequest) ProtoMessage() {} + +func (x *DescribeOTPAuthRequest) ProtoReflect() protoreflect.Message { + mi := &file_apps_otp_pb_request_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DescribeOTPAuthRequest.ProtoReflect.Descriptor instead. +func (*DescribeOTPAuthRequest) Descriptor() ([]byte, []int) { + return file_apps_otp_pb_request_proto_rawDescGZIP(), []int{1} +} + +func (x *DescribeOTPAuthRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +// DeleteOTPAuthRequest 删除OTP请求 +type DeleteOTPAuthRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // 关联用户 + // @gotags: json:"account" validate:"required" + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account" validate:"required"` +} + +func (x *DeleteOTPAuthRequest) Reset() { + *x = DeleteOTPAuthRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_otp_pb_request_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteOTPAuthRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteOTPAuthRequest) ProtoMessage() {} + +func (x *DeleteOTPAuthRequest) ProtoReflect() protoreflect.Message { + mi := &file_apps_otp_pb_request_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeleteOTPAuthRequest.ProtoReflect.Descriptor instead. +func (*DeleteOTPAuthRequest) Descriptor() ([]byte, []int) { + return file_apps_otp_pb_request_proto_rawDescGZIP(), []int{2} +} + +func (x *DeleteOTPAuthRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +// 启用OTP +type EnableOTPAuthRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // 关联用户 + // @gotags: json:"account" validate:"required" + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account" validate:"required"` +} + +func (x *EnableOTPAuthRequest) Reset() { + *x = EnableOTPAuthRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_otp_pb_request_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EnableOTPAuthRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EnableOTPAuthRequest) ProtoMessage() {} + +func (x *EnableOTPAuthRequest) ProtoReflect() protoreflect.Message { + mi := &file_apps_otp_pb_request_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EnableOTPAuthRequest.ProtoReflect.Descriptor instead. +func (*EnableOTPAuthRequest) Descriptor() ([]byte, []int) { + return file_apps_otp_pb_request_proto_rawDescGZIP(), []int{3} +} + +func (x *EnableOTPAuthRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +// 禁用OTP +type DisableOTPAuthRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // 关联用户 + // @gotags: json:"account" validate:"required" + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account" validate:"required"` +} + +func (x *DisableOTPAuthRequest) Reset() { + *x = DisableOTPAuthRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_otp_pb_request_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DisableOTPAuthRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DisableOTPAuthRequest) ProtoMessage() {} + +func (x *DisableOTPAuthRequest) ProtoReflect() protoreflect.Message { + mi := &file_apps_otp_pb_request_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DisableOTPAuthRequest.ProtoReflect.Descriptor instead. +func (*DisableOTPAuthRequest) Descriptor() ([]byte, []int) { + return file_apps_otp_pb_request_proto_rawDescGZIP(), []int{4} +} + +func (x *DisableOTPAuthRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +type UpdateOTPStatusRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // 关联用户 + // @gotags: json:"account" validate:"required" + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account" validate:"required"` + // OTP是否开启 + // @gotags: json:"otp_status" validate:"required" + OtpStatus OTPStatus `protobuf:"varint,2,opt,name=otp_status,json=otpStatus,proto3,enum=infraboard.keyauth.otp.OTPStatus" json:"otp_status" validate:"required"` +} + +func (x *UpdateOTPStatusRequest) Reset() { + *x = UpdateOTPStatusRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_otp_pb_request_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateOTPStatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateOTPStatusRequest) ProtoMessage() {} + +func (x *UpdateOTPStatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_apps_otp_pb_request_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateOTPStatusRequest.ProtoReflect.Descriptor instead. +func (*UpdateOTPStatusRequest) Descriptor() ([]byte, []int) { + return file_apps_otp_pb_request_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateOTPStatusRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +func (x *UpdateOTPStatusRequest) GetOtpStatus() OTPStatus { + if x != nil { + return x.OtpStatus + } + return OTPStatus_UNKNOWN +} + +var File_apps_otp_pb_request_proto protoreflect.FileDescriptor + +var file_apps_otp_pb_request_proto_rawDesc = []byte{ + 0x0a, 0x19, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x2f, 0x70, 0x62, 0x2f, 0x72, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x16, 0x69, 0x6e, 0x66, + 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, + 0x6f, 0x74, 0x70, 0x1a, 0x15, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x2f, 0x70, 0x62, + 0x2f, 0x6f, 0x74, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x30, 0x0a, 0x14, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x32, 0x0a, 0x16, + 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x22, 0x30, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, + 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, + 0x6e, 0x74, 0x22, 0x30, 0x0a, 0x14, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x54, 0x50, 0x41, + 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x31, 0x0a, 0x15, 0x44, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x4f, + 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x74, 0x0a, 0x16, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x4f, 0x54, 0x50, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x40, 0x0a, 0x0a, 0x6f, + 0x74, 0x70, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, + 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, + 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x4f, 0x54, 0x50, 0x53, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x52, 0x09, 0x6f, 0x74, 0x70, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x28, 0x5a, + 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, + 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, + 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_apps_otp_pb_request_proto_rawDescOnce sync.Once + file_apps_otp_pb_request_proto_rawDescData = file_apps_otp_pb_request_proto_rawDesc +) + +func file_apps_otp_pb_request_proto_rawDescGZIP() []byte { + file_apps_otp_pb_request_proto_rawDescOnce.Do(func() { + file_apps_otp_pb_request_proto_rawDescData = protoimpl.X.CompressGZIP(file_apps_otp_pb_request_proto_rawDescData) + }) + return file_apps_otp_pb_request_proto_rawDescData +} + +var file_apps_otp_pb_request_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_apps_otp_pb_request_proto_goTypes = []interface{}{ + (*CreateOTPAuthRequest)(nil), // 0: infraboard.keyauth.otp.CreateOTPAuthRequest + (*DescribeOTPAuthRequest)(nil), // 1: infraboard.keyauth.otp.DescribeOTPAuthRequest + (*DeleteOTPAuthRequest)(nil), // 2: infraboard.keyauth.otp.DeleteOTPAuthRequest + (*EnableOTPAuthRequest)(nil), // 3: infraboard.keyauth.otp.EnableOTPAuthRequest + (*DisableOTPAuthRequest)(nil), // 4: infraboard.keyauth.otp.DisableOTPAuthRequest + (*UpdateOTPStatusRequest)(nil), // 5: infraboard.keyauth.otp.UpdateOTPStatusRequest + (OTPStatus)(0), // 6: infraboard.keyauth.otp.OTPStatus +} +var file_apps_otp_pb_request_proto_depIdxs = []int32{ + 6, // 0: infraboard.keyauth.otp.UpdateOTPStatusRequest.otp_status:type_name -> infraboard.keyauth.otp.OTPStatus + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_apps_otp_pb_request_proto_init() } +func file_apps_otp_pb_request_proto_init() { + if File_apps_otp_pb_request_proto != nil { + return + } + file_apps_otp_pb_otp_proto_init() + if !protoimpl.UnsafeEnabled { + file_apps_otp_pb_request_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateOTPAuthRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_apps_otp_pb_request_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DescribeOTPAuthRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_apps_otp_pb_request_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteOTPAuthRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_apps_otp_pb_request_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EnableOTPAuthRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_apps_otp_pb_request_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DisableOTPAuthRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_apps_otp_pb_request_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateOTPStatusRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_apps_otp_pb_request_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_apps_otp_pb_request_proto_goTypes, + DependencyIndexes: file_apps_otp_pb_request_proto_depIdxs, + MessageInfos: file_apps_otp_pb_request_proto_msgTypes, + }.Build() + File_apps_otp_pb_request_proto = out.File + file_apps_otp_pb_request_proto_rawDesc = nil + file_apps_otp_pb_request_proto_goTypes = nil + file_apps_otp_pb_request_proto_depIdxs = nil +} diff --git a/apps/otp/request_ext.go b/apps/otp/request_ext.go new file mode 100644 index 00000000..f265c1bd --- /dev/null +++ b/apps/otp/request_ext.go @@ -0,0 +1,68 @@ +package otp + +import "github.com/go-playground/validator/v10" + +// CreateOTPAuth(context.Context, *CreateOTPAuthRequest) (*OTPAuth, error) +// DescribeOTPAuth(context.Context, *DescribeOTPAuthRequest) (*OTPAuth, error) +// DeleteOTPAuth(context.Context, *DeleteOTPAuthRequest) (*OTPAuth, error) +// PatchOTPAuth(context.Context, *PatchOTPAuthRequest) (*OTPAuth, error) + +var ( + validate = validator.New() +) + +func NewCreateOTPAuthRequestWithName(accountname string) *CreateOTPAuthRequest { + return &CreateOTPAuthRequest{ + Account: accountname, + } +} + +func NewCreateOTPAuthRequest() *CreateOTPAuthRequest { + return &CreateOTPAuthRequest{} +} + +func (req *CreateOTPAuthRequest) Validate() error { + return validate.Struct(req) +} + +func NewDescribeOTPAuthRequestWithName(accountname string) *DescribeOTPAuthRequest { + return &DescribeOTPAuthRequest{ + Account: accountname, + } +} + +func (req *DescribeOTPAuthRequest) Validate() error { + return validate.Struct(req) +} +func NewDeleteOTPAuthRequestWithName(accountname string) *DeleteOTPAuthRequest { + return &DeleteOTPAuthRequest{ + Account: accountname, + } +} + +func (req *DeleteOTPAuthRequest) Validate() error { + return validate.Struct(req) +} + +// func NewEnableOTPAuthRequest() *EnableOTPAuthRequest { +// return &EnableOTPAuthRequest{} +// } + +// func (req *EnableOTPAuthRequest) Validate() error { +// return validate.Struct(req) +// } + +// func NewDisableOTPAuthRequest() *DisableOTPAuthRequest { +// return &DisableOTPAuthRequest{} +// } + +// func (req *DisableOTPAuthRequest) Validate() error { +// return validate.Struct(req) +// } +func NewUpdateOTPStatusRequest() *UpdateOTPStatusRequest { + return &UpdateOTPStatusRequest{} +} + +func (req *UpdateOTPStatusRequest) Validate() error { + return validate.Struct(req) +} diff --git a/apps/otp/service.pb.go b/apps/otp/service.pb.go new file mode 100644 index 00000000..268520a8 --- /dev/null +++ b/apps/otp/service.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.1 +// source: apps/otp/pb/service.proto + +package otp + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +var File_apps_otp_pb_service_proto protoreflect.FileDescriptor + +var file_apps_otp_pb_service_proto_rawDesc = []byte{ + 0x0a, 0x19, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x16, 0x69, 0x6e, 0x66, + 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, + 0x6f, 0x74, 0x70, 0x1a, 0x19, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x2f, 0x70, 0x62, + 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x15, + 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x2f, 0x70, 0x62, 0x2f, 0x6f, 0x74, 0x70, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x95, 0x03, 0x0a, 0x07, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x5e, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4f, 0x54, 0x50, 0x41, 0x75, + 0x74, 0x68, 0x12, 0x2c, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, + 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1f, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, + 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, + 0x68, 0x12, 0x62, 0x0a, 0x0f, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x4f, 0x54, 0x50, + 0x41, 0x75, 0x74, 0x68, 0x12, 0x2e, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, + 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x44, 0x65, + 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, + 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x4f, 0x54, + 0x50, 0x41, 0x75, 0x74, 0x68, 0x12, 0x5e, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4f, + 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x12, 0x2c, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, + 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, + 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x4f, 0x54, + 0x50, 0x41, 0x75, 0x74, 0x68, 0x12, 0x66, 0x0a, 0x13, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, + 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2e, 0x2e, 0x69, + 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, + 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x54, 0x50, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x69, + 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, + 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x4f, 0x54, 0x50, 0x41, 0x75, 0x74, 0x68, 0x42, 0x28, 0x5a, + 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, + 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, + 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var file_apps_otp_pb_service_proto_goTypes = []interface{}{ + (*CreateOTPAuthRequest)(nil), // 0: infraboard.keyauth.otp.CreateOTPAuthRequest + (*DescribeOTPAuthRequest)(nil), // 1: infraboard.keyauth.otp.DescribeOTPAuthRequest + (*DeleteOTPAuthRequest)(nil), // 2: infraboard.keyauth.otp.DeleteOTPAuthRequest + (*UpdateOTPStatusRequest)(nil), // 3: infraboard.keyauth.otp.UpdateOTPStatusRequest + (*OTPAuth)(nil), // 4: infraboard.keyauth.otp.OTPAuth +} +var file_apps_otp_pb_service_proto_depIdxs = []int32{ + 0, // 0: infraboard.keyauth.otp.Service.CreateOTPAuth:input_type -> infraboard.keyauth.otp.CreateOTPAuthRequest + 1, // 1: infraboard.keyauth.otp.Service.DescribeOTPAuth:input_type -> infraboard.keyauth.otp.DescribeOTPAuthRequest + 2, // 2: infraboard.keyauth.otp.Service.DeleteOTPAuth:input_type -> infraboard.keyauth.otp.DeleteOTPAuthRequest + 3, // 3: infraboard.keyauth.otp.Service.UpdateOTPAuthStatus:input_type -> infraboard.keyauth.otp.UpdateOTPStatusRequest + 4, // 4: infraboard.keyauth.otp.Service.CreateOTPAuth:output_type -> infraboard.keyauth.otp.OTPAuth + 4, // 5: infraboard.keyauth.otp.Service.DescribeOTPAuth:output_type -> infraboard.keyauth.otp.OTPAuth + 4, // 6: infraboard.keyauth.otp.Service.DeleteOTPAuth:output_type -> infraboard.keyauth.otp.OTPAuth + 4, // 7: infraboard.keyauth.otp.Service.UpdateOTPAuthStatus:output_type -> infraboard.keyauth.otp.OTPAuth + 4, // [4:8] is the sub-list for method output_type + 0, // [0:4] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_apps_otp_pb_service_proto_init() } +func file_apps_otp_pb_service_proto_init() { + if File_apps_otp_pb_service_proto != nil { + return + } + file_apps_otp_pb_request_proto_init() + file_apps_otp_pb_otp_proto_init() + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_apps_otp_pb_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_apps_otp_pb_service_proto_goTypes, + DependencyIndexes: file_apps_otp_pb_service_proto_depIdxs, + }.Build() + File_apps_otp_pb_service_proto = out.File + file_apps_otp_pb_service_proto_rawDesc = nil + file_apps_otp_pb_service_proto_goTypes = nil + file_apps_otp_pb_service_proto_depIdxs = nil +} diff --git a/apps/otp/service_grpc.pb.go b/apps/otp/service_grpc.pb.go new file mode 100644 index 00000000..187bcb25 --- /dev/null +++ b/apps/otp/service_grpc.pb.go @@ -0,0 +1,213 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.1 +// source: apps/otp/pb/service.proto + +package otp + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// ServiceClient is the client API for Service service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ServiceClient interface { + CreateOTPAuth(ctx context.Context, in *CreateOTPAuthRequest, opts ...grpc.CallOption) (*OTPAuth, error) + DescribeOTPAuth(ctx context.Context, in *DescribeOTPAuthRequest, opts ...grpc.CallOption) (*OTPAuth, error) + DeleteOTPAuth(ctx context.Context, in *DeleteOTPAuthRequest, opts ...grpc.CallOption) (*OTPAuth, error) + UpdateOTPAuthStatus(ctx context.Context, in *UpdateOTPStatusRequest, opts ...grpc.CallOption) (*OTPAuth, error) +} + +type serviceClient struct { + cc grpc.ClientConnInterface +} + +func NewServiceClient(cc grpc.ClientConnInterface) ServiceClient { + return &serviceClient{cc} +} + +func (c *serviceClient) CreateOTPAuth(ctx context.Context, in *CreateOTPAuthRequest, opts ...grpc.CallOption) (*OTPAuth, error) { + out := new(OTPAuth) + err := c.cc.Invoke(ctx, "/infraboard.keyauth.otp.Service/CreateOTPAuth", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serviceClient) DescribeOTPAuth(ctx context.Context, in *DescribeOTPAuthRequest, opts ...grpc.CallOption) (*OTPAuth, error) { + out := new(OTPAuth) + err := c.cc.Invoke(ctx, "/infraboard.keyauth.otp.Service/DescribeOTPAuth", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serviceClient) DeleteOTPAuth(ctx context.Context, in *DeleteOTPAuthRequest, opts ...grpc.CallOption) (*OTPAuth, error) { + out := new(OTPAuth) + err := c.cc.Invoke(ctx, "/infraboard.keyauth.otp.Service/DeleteOTPAuth", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serviceClient) UpdateOTPAuthStatus(ctx context.Context, in *UpdateOTPStatusRequest, opts ...grpc.CallOption) (*OTPAuth, error) { + out := new(OTPAuth) + err := c.cc.Invoke(ctx, "/infraboard.keyauth.otp.Service/UpdateOTPAuthStatus", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ServiceServer is the server API for Service service. +// All implementations must embed UnimplementedServiceServer +// for forward compatibility +type ServiceServer interface { + CreateOTPAuth(context.Context, *CreateOTPAuthRequest) (*OTPAuth, error) + DescribeOTPAuth(context.Context, *DescribeOTPAuthRequest) (*OTPAuth, error) + DeleteOTPAuth(context.Context, *DeleteOTPAuthRequest) (*OTPAuth, error) + UpdateOTPAuthStatus(context.Context, *UpdateOTPStatusRequest) (*OTPAuth, error) + mustEmbedUnimplementedServiceServer() +} + +// UnimplementedServiceServer must be embedded to have forward compatible implementations. +type UnimplementedServiceServer struct { +} + +func (UnimplementedServiceServer) CreateOTPAuth(context.Context, *CreateOTPAuthRequest) (*OTPAuth, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateOTPAuth not implemented") +} +func (UnimplementedServiceServer) DescribeOTPAuth(context.Context, *DescribeOTPAuthRequest) (*OTPAuth, error) { + return nil, status.Errorf(codes.Unimplemented, "method DescribeOTPAuth not implemented") +} +func (UnimplementedServiceServer) DeleteOTPAuth(context.Context, *DeleteOTPAuthRequest) (*OTPAuth, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeleteOTPAuth not implemented") +} +func (UnimplementedServiceServer) UpdateOTPAuthStatus(context.Context, *UpdateOTPStatusRequest) (*OTPAuth, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateOTPAuthStatus not implemented") +} +func (UnimplementedServiceServer) mustEmbedUnimplementedServiceServer() {} + +// UnsafeServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ServiceServer will +// result in compilation errors. +type UnsafeServiceServer interface { + mustEmbedUnimplementedServiceServer() +} + +func RegisterServiceServer(s grpc.ServiceRegistrar, srv ServiceServer) { + s.RegisterService(&Service_ServiceDesc, srv) +} + +func _Service_CreateOTPAuth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateOTPAuthRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).CreateOTPAuth(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/infraboard.keyauth.otp.Service/CreateOTPAuth", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).CreateOTPAuth(ctx, req.(*CreateOTPAuthRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Service_DescribeOTPAuth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DescribeOTPAuthRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).DescribeOTPAuth(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/infraboard.keyauth.otp.Service/DescribeOTPAuth", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).DescribeOTPAuth(ctx, req.(*DescribeOTPAuthRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Service_DeleteOTPAuth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteOTPAuthRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).DeleteOTPAuth(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/infraboard.keyauth.otp.Service/DeleteOTPAuth", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).DeleteOTPAuth(ctx, req.(*DeleteOTPAuthRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Service_UpdateOTPAuthStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateOTPStatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).UpdateOTPAuthStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/infraboard.keyauth.otp.Service/UpdateOTPAuthStatus", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).UpdateOTPAuthStatus(ctx, req.(*UpdateOTPStatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Service_ServiceDesc is the grpc.ServiceDesc for Service service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Service_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "infraboard.keyauth.otp.Service", + HandlerType: (*ServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateOTPAuth", + Handler: _Service_CreateOTPAuth_Handler, + }, + { + MethodName: "DescribeOTPAuth", + Handler: _Service_DescribeOTPAuth_Handler, + }, + { + MethodName: "DeleteOTPAuth", + Handler: _Service_DeleteOTPAuth_Handler, + }, + { + MethodName: "UpdateOTPAuthStatus", + Handler: _Service_UpdateOTPAuthStatus_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "apps/otp/pb/service.proto", +} diff --git a/apps/token/issuer/issuer.go b/apps/token/issuer/issuer.go index b05f033f..9f120238 100644 --- a/apps/token/issuer/issuer.go +++ b/apps/token/issuer/issuer.go @@ -15,6 +15,7 @@ import ( "github.com/infraboard/mcube/logger/zap" "github.com/rs/xid" + "github.com/infraboard/keyauth/apps/otp" wechatWork "github.com/infraboard/keyauth/apps/wxwork" "github.com/infraboard/keyauth/apps/application" @@ -37,6 +38,7 @@ func NewTokenIssuer() (Issuer, error) { ldap: app.GetInternalApp(provider.AppName).(provider.LDAP), wechatWork: app.GetInternalApp(wechatWork.AppName).(wechatWork.WechatWork), app: app.GetGrpcApp(application.AppName).(application.ServiceServer), + otp: app.GetGrpcApp(otp.AppName).(otp.ServiceServer), emailRE: regexp.MustCompile(`([a-zA-Z0-9]+)@([a-zA-Z0-9\.]+)\.([a-zA-Z0-9]+)`), log: zap.L().Named("Token Issuer"), } @@ -52,6 +54,7 @@ type issuer struct { ldap provider.LDAP wechatWork wechatWork.WechatWork emailRE *regexp.Regexp + otp otp.ServiceServer log logger.Logger } @@ -266,6 +269,28 @@ func (i *issuer) IssueToken(ctx context.Context, req *token.IssueTokenRequest) ( return nil, exception.NewInternalServerError("not impl") case token.GrantType_AUTH_CODE: return nil, exception.NewInternalServerError("not impl") + case token.GrantType_OTP_CODE: + // 判断用户的otp是否正确,正确则颁发token + descReq := user.NewDescriptAccountRequestWithAccount(req.Username) + u, err := i.user.DescribeAccount(ctx, descReq) + if err != nil { + return nil, exception.NewBadRequest(err.Error()) + } + if u.OtpStatus == otp.OTPStatus_DISABLED { + return nil, errors.New("OTP disabled, please enable it first") + } + descOtpReq := otp.NewDescribeOTPAuthRequestWithName(req.Username) + fmt.Println(descOtpReq) + ins, err := i.otp.DescribeOTPAuth(ctx, descOtpReq) + if err != nil { + return nil, err + } + otpsecret, _ := ins.GenCode(ins.SecretKey) + if otpsecret != req.OtpCode { + return nil, exception.NewUnauthorized("OTP code is not correct") + } + tk := i.issueUserToken(app, u, token.GrantType_OTP_CODE) + return tk, nil default: return nil, exception.NewInternalServerError("unknown grant type %s", req.GrantType) } diff --git a/apps/token/pb/request.proto b/apps/token/pb/request.proto index e6f9ca04..8e7cde24 100644 --- a/apps/token/pb/request.proto +++ b/apps/token/pb/request.proto @@ -36,6 +36,7 @@ message IssueTokenRequest { string user_agent = 13; string remote_ip = 14; string service = 17; + string otp_code = 18; } message RevolkTokenRequest { diff --git a/apps/token/pb/token.proto b/apps/token/pb/token.proto index 3df689a3..c0a1f394 100644 --- a/apps/token/pb/token.proto +++ b/apps/token/pb/token.proto @@ -16,6 +16,7 @@ enum GrantType { AUTH_CODE = 7; IMPLICIT = 8; WECHAT_WORK = 9; + OTP_CODE = 10; } enum TokenType { diff --git a/apps/token/request.ext.go b/apps/token/request.ext.go index 929b0ef2..810b675b 100644 --- a/apps/token/request.ext.go +++ b/apps/token/request.ext.go @@ -132,6 +132,10 @@ func (m *IssueTokenRequest) Validate() error { if m.State == "" || m.Service == "" { return fmt.Errorf("use %s grant type, state required", GrantType_WECHAT_WORK) } + case GrantType_OTP_CODE: + if m.OtpCode == "" { + return fmt.Errorf("user %s grant type, otp_code required", GrantType_OTP_CODE) + } default: return fmt.Errorf("unknown grant type %s", m.GrantType) } diff --git a/apps/token/request.pb.go b/apps/token/request.pb.go index feef9920..3c97d7eb 100644 --- a/apps/token/request.pb.go +++ b/apps/token/request.pb.go @@ -169,6 +169,7 @@ type IssueTokenRequest struct { UserAgent string `protobuf:"bytes,13,opt,name=user_agent,json=userAgent,proto3" json:"user_agent,omitempty"` RemoteIp string `protobuf:"bytes,14,opt,name=remote_ip,json=remoteIp,proto3" json:"remote_ip,omitempty"` Service string `protobuf:"bytes,17,opt,name=service,proto3" json:"service,omitempty"` + OtpCode string `protobuf:"bytes,18,opt,name=otp_code,json=otpCode,proto3" json:"otp_code,omitempty"` } func (x *IssueTokenRequest) Reset() { @@ -322,6 +323,13 @@ func (x *IssueTokenRequest) GetService() string { return "" } +func (x *IssueTokenRequest) GetOtpCode() string { + if x != nil { + return x.OtpCode + } + return "" +} + type RevolkTokenRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -745,7 +753,7 @@ var file_apps_token_pb_request_proto_rawDesc = []byte{ 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, - 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0xe0, 0x04, 0x0a, 0x11, 0x49, 0x73, 0x73, 0x75, + 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0xfb, 0x04, 0x0a, 0x11, 0x49, 0x73, 0x73, 0x75, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6c, @@ -783,64 +791,65 @@ var file_apps_token_pb_request_proto_rawDesc = []byte{ 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5f, 0x69, 0x70, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x49, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0xc5, 0x01, 0x0a, 0x12, 0x52, - 0x65, 0x76, 0x6f, 0x6c, 0x6b, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x23, - 0x0a, 0x0d, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x63, - 0x72, 0x65, 0x74, 0x12, 0x25, 0x0a, 0x0e, 0x6c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x65, - 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x6c, 0x6f, 0x67, - 0x6f, 0x75, 0x74, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, - 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x23, 0x0a, - 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, - 0x65, 0x6e, 0x22, 0xd0, 0x01, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x54, 0x6f, 0x6b, 0x65, - 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x36, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, - 0x61, 0x72, 0x64, 0x2e, 0x6d, 0x63, 0x75, 0x62, 0x65, 0x2e, 0x70, 0x61, 0x67, 0x65, 0x2e, 0x50, - 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, - 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, - 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x12, 0x42, 0x0a, 0x0a, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, - 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x2e, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x09, 0x67, 0x72, 0x61, 0x6e, - 0x74, 0x54, 0x79, 0x70, 0x65, 0x22, 0x9d, 0x01, 0x0a, 0x11, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, - 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x61, - 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x21, - 0x0a, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, - 0x6e, 0x12, 0x42, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, - 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x54, 0x79, 0x70, 0x65, 0x22, 0x4c, 0x0a, 0x16, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x4e, - 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x14, 0x0a, - 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, - 0x6b, 0x65, 0x6e, 0x22, 0x69, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x6f, 0x6b, - 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, - 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x0a, 0x06, - 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, - 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x61, - 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, - 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x61, 0x69, - 0x6c, 0x65, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x66, 0x61, 0x69, 0x6c, 0x65, - 0x64, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, - 0x74, 0x68, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x09, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x74, + 0x70, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x74, + 0x70, 0x43, 0x6f, 0x64, 0x65, 0x22, 0xc5, 0x01, 0x0a, 0x12, 0x52, 0x65, 0x76, 0x6f, 0x6c, 0x6b, + 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, + 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6c, 0x69, + 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, 0x25, + 0x0a, 0x0e, 0x6c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x6c, 0x6f, 0x67, 0x6f, 0x75, 0x74, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, + 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0xd0, 0x01, + 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x36, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x22, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6d, + 0x63, 0x75, 0x62, 0x65, 0x2e, 0x70, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x42, 0x0a, 0x0a, + 0x67, 0x72, 0x61, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, + 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x47, 0x72, 0x61, 0x6e, + 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x09, 0x67, 0x72, 0x61, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, + 0x22, 0x9d, 0x01, 0x0a, 0x11, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x42, 0x0a, 0x0a, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, + 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x54, 0x79, 0x70, 0x65, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x79, 0x70, 0x65, + 0x22, 0x4c, 0x0a, 0x16, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x69, + 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, + 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, + 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x61, 0x0a, 0x13, 0x44, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x75, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x06, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x42, 0x2a, 0x5a, 0x28, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, + 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, + 0x70, 0x73, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/apps/token/token.pb.go b/apps/token/token.pb.go index e3aad070..a8413158 100644 --- a/apps/token/token.pb.go +++ b/apps/token/token.pb.go @@ -34,21 +34,23 @@ const ( GrantType_AUTH_CODE GrantType = 7 GrantType_IMPLICIT GrantType = 8 GrantType_WECHAT_WORK GrantType = 9 + GrantType_OTP_CODE GrantType = 10 ) // Enum value maps for GrantType. var ( GrantType_name = map[int32]string{ - 0: "NULL", - 1: "UNKNOWN", - 2: "PASSWORD", - 3: "LDAP", - 4: "REFRESH", - 5: "ACCESS", - 6: "CLIENT", - 7: "AUTH_CODE", - 8: "IMPLICIT", - 9: "WECHAT_WORK", + 0: "NULL", + 1: "UNKNOWN", + 2: "PASSWORD", + 3: "LDAP", + 4: "REFRESH", + 5: "ACCESS", + 6: "CLIENT", + 7: "AUTH_CODE", + 8: "IMPLICIT", + 9: "WECHAT_WORK", + 10: "OTP_CODE", } GrantType_value = map[string]int32{ "NULL": 0, @@ -61,6 +63,7 @@ var ( "AUTH_CODE": 7, "IMPLICIT": 8, "WECHAT_WORK": 9, + "OTP_CODE": 10, } ) @@ -601,7 +604,7 @@ var file_apps_token_pb_token_proto_rawDesc = []byte{ 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05, 0x69, - 0x74, 0x65, 0x6d, 0x73, 0x2a, 0x8d, 0x01, 0x0a, 0x09, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x54, 0x79, + 0x74, 0x65, 0x6d, 0x73, 0x2a, 0x9b, 0x01, 0x0a, 0x09, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x55, 0x4c, 0x4c, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x41, 0x53, 0x53, 0x57, 0x4f, 0x52, 0x44, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x44, 0x41, 0x50, 0x10, @@ -610,20 +613,21 @@ var file_apps_token_pb_token_proto_rawDesc = []byte{ 0x49, 0x45, 0x4e, 0x54, 0x10, 0x06, 0x12, 0x0d, 0x0a, 0x09, 0x41, 0x55, 0x54, 0x48, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x49, 0x4d, 0x50, 0x4c, 0x49, 0x43, 0x49, 0x54, 0x10, 0x08, 0x12, 0x0f, 0x0a, 0x0b, 0x57, 0x45, 0x43, 0x48, 0x41, 0x54, 0x5f, 0x57, 0x4f, - 0x52, 0x4b, 0x10, 0x09, 0x2a, 0x29, 0x0a, 0x09, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x42, 0x45, 0x41, 0x52, 0x45, 0x52, 0x10, 0x00, 0x12, 0x07, 0x0a, - 0x03, 0x4d, 0x41, 0x43, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x4a, 0x57, 0x54, 0x10, 0x02, 0x2a, - 0x72, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, - 0x53, 0x45, 0x53, 0x53, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x49, 0x4e, 0x41, 0x54, - 0x45, 0x44, 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x16, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x5f, 0x43, 0x4c, - 0x49, 0x45, 0x4e, 0x54, 0x5f, 0x4c, 0x4f, 0x47, 0x47, 0x45, 0x44, 0x5f, 0x49, 0x4e, 0x10, 0x01, - 0x12, 0x19, 0x0a, 0x15, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x5f, 0x50, 0x4c, 0x41, 0x43, 0x45, 0x5f, - 0x4c, 0x4f, 0x47, 0x47, 0x45, 0x44, 0x5f, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x16, 0x0a, 0x12, 0x4f, - 0x54, 0x48, 0x45, 0x52, 0x5f, 0x49, 0x50, 0x5f, 0x4c, 0x4f, 0x47, 0x47, 0x45, 0x44, 0x5f, 0x49, - 0x4e, 0x10, 0x03, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, - 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x4b, 0x10, 0x09, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x54, 0x50, 0x5f, 0x43, 0x4f, 0x44, 0x45, + 0x10, 0x0a, 0x2a, 0x29, 0x0a, 0x09, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x0a, 0x0a, 0x06, 0x42, 0x45, 0x41, 0x52, 0x45, 0x52, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4d, + 0x41, 0x43, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x4a, 0x57, 0x54, 0x10, 0x02, 0x2a, 0x72, 0x0a, + 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x45, + 0x53, 0x53, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x44, + 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x16, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x5f, 0x43, 0x4c, 0x49, 0x45, + 0x4e, 0x54, 0x5f, 0x4c, 0x4f, 0x47, 0x47, 0x45, 0x44, 0x5f, 0x49, 0x4e, 0x10, 0x01, 0x12, 0x19, + 0x0a, 0x15, 0x4f, 0x54, 0x48, 0x45, 0x52, 0x5f, 0x50, 0x4c, 0x41, 0x43, 0x45, 0x5f, 0x4c, 0x4f, + 0x47, 0x47, 0x45, 0x44, 0x5f, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x16, 0x0a, 0x12, 0x4f, 0x54, 0x48, + 0x45, 0x52, 0x5f, 0x49, 0x50, 0x5f, 0x4c, 0x4f, 0x47, 0x47, 0x45, 0x44, 0x5f, 0x49, 0x4e, 0x10, + 0x03, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, + 0x74, 0x68, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/apps/user/impl/impl.go b/apps/user/impl/impl.go index 8d1254a1..c5b0db71 100644 --- a/apps/user/impl/impl.go +++ b/apps/user/impl/impl.go @@ -12,6 +12,7 @@ import ( "github.com/infraboard/keyauth/apps/department" "github.com/infraboard/keyauth/apps/domain" + "github.com/infraboard/keyauth/apps/otp" "github.com/infraboard/keyauth/apps/policy" "github.com/infraboard/keyauth/apps/user" "github.com/infraboard/keyauth/conf" @@ -28,6 +29,7 @@ type service struct { policy policy.ServiceServer depart department.ServiceServer domain domain.ServiceServer + otp otp.ServiceServer user.UnimplementedServiceServer } @@ -36,6 +38,7 @@ func (s *service) Config() error { s.policy = app.GetGrpcApp(policy.AppName).(policy.ServiceServer) s.depart = app.GetGrpcApp(department.AppName).(department.ServiceServer) s.domain = app.GetGrpcApp(domain.AppName).(domain.ServiceServer) + s.otp = app.GetGrpcApp(otp.AppName).(otp.ServiceServer) db := conf.C().Mongo.GetDB() uc := db.Collection("user") diff --git a/apps/user/impl/user.go b/apps/user/impl/user.go index 98d2b567..6cea2968 100644 --- a/apps/user/impl/user.go +++ b/apps/user/impl/user.go @@ -10,6 +10,7 @@ import ( "go.mongodb.org/mongo-driver/mongo" "github.com/infraboard/keyauth/apps/domain" + "github.com/infraboard/keyauth/apps/otp" "github.com/infraboard/keyauth/apps/policy" "github.com/infraboard/keyauth/apps/user" "github.com/infraboard/keyauth/common/password" @@ -29,12 +30,19 @@ func (s *service) CreateAccount(ctx context.Context, req *user.CreateAccountRequ if err != nil { return nil, err } - // 如果是管理员创建的账号需要用户自己重置密码 if u.CreateType.IsIn(user.CreateType_DOMAIN_CREATED) { u.HashedPassword.SetNeedReset("admin created user need reset when first login") } + if req.OtpEnabled { + _, err := s.otp.CreateOTPAuth(ctx, otp.NewCreateOTPAuthRequestWithName(req.Account)) + if err != nil { + return nil, err + } + u.OtpStatus = otp.OTPStatus_ENABLED + } + if err := s.saveAccount(u); err != nil { return nil, err } @@ -232,3 +240,24 @@ func (s *service) GeneratePassword(ctx context.Context, req *user.GeneratePasswo } return user.NewGeneratePasswordResponse(*ranPass), nil } + +func (s *service) UpdateOTPStatus(ctx context.Context, req *user.UpdateOTPStatusRequest) (*user.User, error) { + if err := req.Validate(); err != nil { + return nil, exception.NewBadRequest("validate update department error, %s", err) + } + + s.log.Debugf(" update %s OTP settings to %s ", req.Account, req.OtpStatus) + u, err := s.DescribeAccount(ctx, user.NewDescriptAccountRequestWithAccount(req.Account)) + if err != nil { + return nil, err + } + u.UpdateAt = ftime.Now().Timestamp() + u.OtpStatus = req.OtpStatus + + _, err = s.col.UpdateOne(context.TODO(), bson.M{"_id": u.Account}, bson.M{"$set": u}) + if err != nil { + return nil, exception.NewInternalServerError("update user(%s) error, %s", u.Account, err) + } + + return u, nil +} diff --git a/apps/user/pb/request.proto b/apps/user/pb/request.proto index 77e91189..d5f257e5 100644 --- a/apps/user/pb/request.proto +++ b/apps/user/pb/request.proto @@ -7,6 +7,7 @@ import "github.com/infraboard/mcube/pb/page/page.proto"; import "apps/user/pb/enum.proto"; import "apps/user/pb/types.proto"; import "common/types/types.proto"; +import "apps/otp/pb/otp.proto"; // Profile todo message Profile { @@ -71,6 +72,9 @@ message CreateAccountRequest { // 密码相关信息 // @gotags: json:"password" validate:"required,lte=80" string password = 8; + // 是否启用OTP + // @gotags: json:"otp_enabled" + bool otp_enabled = 10; } // DescribeAccountRequest 查询用户详情请求 @@ -117,7 +121,10 @@ message UpdateAccountRequest { string department_id = 3; // profile 账号profile // @gotags: json:"profile" - Profile profile = 4; + Profile profile = 4; + // 动态令牌是否开启 + // @gotags: bson:"otp_enabled" json:"otp_enabled" + bool otp_enabled = 16; } // UpdatePasswordRequest todo @@ -164,4 +171,12 @@ message UnBlockAccountRequest { message DeleteAccountRequest { // @gotags: json:"account" string account = 1; -} \ No newline at end of file +} + +// OTPSettingsRequest 变更OTP设置 +message UpdateOTPStatusRequest { + // @gotags: json:"account" validate:"required" + string account = 1; + // @gotags: json:"otp_status" validate:"required" + otp.OTPStatus otp_status = 16; +} diff --git a/apps/user/pb/service.proto b/apps/user/pb/service.proto index 6f7f360e..7228aab1 100644 --- a/apps/user/pb/service.proto +++ b/apps/user/pb/service.proto @@ -26,4 +26,6 @@ service Service { rpc UpdateAccountPassword(UpdatePasswordRequest) returns(Password); // GeneratePassword 生成符合检测强度的随机密码 rpc GeneratePassword(GeneratePasswordRequest) returns(GeneratePasswordResponse); -} + // 开启或关闭OTP + rpc UpdateOTPStatus(UpdateOTPStatusRequest) returns (User); +} \ No newline at end of file diff --git a/apps/user/pb/user.proto b/apps/user/pb/user.proto index b0f29f72..daaf5370 100644 --- a/apps/user/pb/user.proto +++ b/apps/user/pb/user.proto @@ -7,6 +7,7 @@ import "apps/department/pb/department.proto"; import "apps/user/pb/types.proto"; import "apps/user/pb/request.proto"; import "apps/user/pb/enum.proto"; +import "apps/otp/pb/otp.proto"; message Password { // hash过后的密码 @@ -95,6 +96,9 @@ message User { // 部门 // @gotags: bson:"-" json:"department,omitempty" department.Department department = 15; + // 动态令牌是否开启 + // @gotags: bson:"otp_enabled" json:"otp_enabled,omitempty" + otp.OTPStatus otp_status = 16; } message Set { diff --git a/apps/user/request.pb.go b/apps/user/request.pb.go index ab6ac094..40e00d94 100644 --- a/apps/user/request.pb.go +++ b/apps/user/request.pb.go @@ -7,6 +7,7 @@ package user import ( + otp "github.com/infraboard/keyauth/apps/otp" types "github.com/infraboard/keyauth/apps/user/types" types1 "github.com/infraboard/keyauth/common/types" request "github.com/infraboard/mcube/http/request" @@ -196,6 +197,9 @@ type CreateAccountRequest struct { // 密码相关信息 // @gotags: json:"password" validate:"required,lte=80" Password string `protobuf:"bytes,8,opt,name=password,proto3" json:"password" validate:"required,lte=80"` + // 是否启用OTP + // @gotags: json:"otp_enabled" + OtpEnabled bool `protobuf:"varint,10,opt,name=otp_enabled,json=otpEnabled,proto3" json:"otp_enabled"` } func (x *CreateAccountRequest) Reset() { @@ -293,6 +297,13 @@ func (x *CreateAccountRequest) GetPassword() string { return "" } +func (x *CreateAccountRequest) GetOtpEnabled() bool { + if x != nil { + return x.OtpEnabled + } + return false +} + // DescribeAccountRequest 查询用户详情请求 type DescribeAccountRequest struct { state protoimpl.MessageState @@ -491,6 +502,9 @@ type UpdateAccountRequest struct { // profile 账号profile // @gotags: json:"profile" Profile *Profile `protobuf:"bytes,4,opt,name=profile,proto3" json:"profile"` + // 动态令牌是否开启 + // @gotags: bson:"otp_enabled" json:"otp_enabled" + OtpEnabled bool `protobuf:"varint,16,opt,name=otp_enabled,json=otpEnabled,proto3" json:"otp_enabled" bson:"otp_enabled"` } func (x *UpdateAccountRequest) Reset() { @@ -553,6 +567,13 @@ func (x *UpdateAccountRequest) GetProfile() *Profile { return nil } +func (x *UpdateAccountRequest) GetOtpEnabled() bool { + if x != nil { + return x.OtpEnabled + } + return false +} + // UpdatePasswordRequest todo type UpdatePasswordRequest struct { state protoimpl.MessageState @@ -892,6 +913,64 @@ func (x *DeleteAccountRequest) GetAccount() string { return "" } +// OTPSettingsRequest 变更OTP设置 +type UpdateOTPStatusRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // @gotags: json:"account" validate:"required" + Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account" validate:"required"` + // @gotags: json:"otp_status" validate:"required" + OtpStatus otp.OTPStatus `protobuf:"varint,16,opt,name=otp_status,json=otpStatus,proto3,enum=infraboard.keyauth.otp.OTPStatus" json:"otp_status" validate:"required"` +} + +func (x *UpdateOTPStatusRequest) Reset() { + *x = UpdateOTPStatusRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_apps_user_pb_request_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateOTPStatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateOTPStatusRequest) ProtoMessage() {} + +func (x *UpdateOTPStatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_apps_user_pb_request_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateOTPStatusRequest.ProtoReflect.Descriptor instead. +func (*UpdateOTPStatusRequest) Descriptor() ([]byte, []int) { + return file_apps_user_pb_request_proto_rawDescGZIP(), []int{11} +} + +func (x *UpdateOTPStatusRequest) GetAccount() string { + if x != nil { + return x.Account + } + return "" +} + +func (x *UpdateOTPStatusRequest) GetOtpStatus() otp.OTPStatus { + if x != nil { + return x.OtpStatus + } + return otp.OTPStatus(0) +} + var File_apps_user_pb_request_proto protoreflect.FileDescriptor var file_apps_user_pb_request_proto_rawDesc = []byte{ @@ -906,123 +985,136 @@ var file_apps_user_pb_request_proto_rawDesc = []byte{ 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x18, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0xa6, 0x02, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x1b, - 0x0a, 0x09, 0x72, 0x65, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x72, 0x65, 0x61, 0x6c, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, - 0x69, 0x63, 0x6b, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x6e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x14, - 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, - 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x37, - 0x0a, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1f, - 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, - 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, - 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, - 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, - 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, - 0x69, 0x74, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x12, - 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x6e, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x6e, 0x63, 0x65, 0x22, 0x90, 0x03, 0x0a, 0x14, - 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x44, 0x0a, 0x0b, - 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, - 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x79, - 0x70, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, + 0x74, 0x6f, 0x1a, 0x15, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, 0x2f, 0x70, 0x62, 0x2f, + 0x6f, 0x74, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa6, 0x02, 0x0a, 0x07, 0x50, 0x72, + 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x6c, 0x5f, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x61, 0x6c, 0x4e, 0x61, + 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x69, 0x63, 0x6b, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, + 0x14, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x37, 0x0a, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1f, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, - 0x55, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x54, 0x79, - 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, - 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x65, 0x70, 0x61, 0x72, - 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, 0x64, 0x61, 0x79, - 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, - 0x44, 0x61, 0x79, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, - 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3a, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, - 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, - 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, - 0x6c, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x08, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x32, - 0x0a, 0x16, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, + 0x47, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x06, 0x67, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x16, + 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, + 0x67, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, + 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x6e, + 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x6e, + 0x63, 0x65, 0x22, 0xb1, 0x03, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x64, + 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, + 0x61, 0x69, 0x6e, 0x12, 0x44, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, + 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, + 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x63, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x75, 0x73, 0x65, + 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x69, + 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, + 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x52, + 0x08, 0x75, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x65, 0x70, + 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x18, + 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x78, 0x70, 0x69, + 0x72, 0x65, 0x73, 0x5f, 0x64, 0x61, 0x79, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, + 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x44, 0x61, 0x79, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x64, + 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3a, 0x0a, + 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, + 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, + 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, + 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, + 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, + 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x74, 0x70, 0x5f, 0x65, 0x6e, 0x61, + 0x62, 0x6c, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x6f, 0x74, 0x70, 0x45, + 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x22, 0x32, 0x0a, 0x16, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, + 0x62, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x8f, 0x03, 0x0a, 0x13, 0x51, + 0x75, 0x65, 0x72, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x36, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x22, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6d, 0x63, + 0x75, 0x62, 0x65, 0x2e, 0x70, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x70, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x3e, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x72, + 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, + 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x52, 0x08, 0x75, 0x73, + 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x27, 0x0a, 0x0f, 0x77, 0x69, 0x74, + 0x68, 0x5f, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x0e, 0x77, 0x69, 0x74, 0x68, 0x44, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, + 0x6e, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, + 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x65, 0x70, 0x61, 0x72, + 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0c, 0x77, 0x69, 0x74, 0x68, 0x5f, + 0x61, 0x6c, 0x6c, 0x5f, 0x73, 0x75, 0x62, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x77, + 0x69, 0x74, 0x68, 0x41, 0x6c, 0x6c, 0x53, 0x75, 0x62, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x6b, 0x69, + 0x70, 0x5f, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x73, + 0x6b, 0x69, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x6b, 0x65, 0x79, 0x77, + 0x6f, 0x72, 0x64, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x77, + 0x6f, 0x72, 0x64, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x0a, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x22, 0xf9, 0x01, 0x0a, + 0x14, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x45, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, + 0x6d, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x24, 0x2e, 0x69, 0x6e, 0x66, + 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, + 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x64, 0x65, + 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, + 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, + 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x3a, 0x0a, 0x07, 0x70, + 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x69, + 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, + 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x07, + 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x74, 0x70, 0x5f, 0x65, + 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x6f, 0x74, + 0x70, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x22, 0x82, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, + 0x6f, 0x6c, 0x64, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x6f, 0x6c, 0x64, 0x50, 0x61, 0x73, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x5f, 0x70, + 0x61, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x77, 0x50, 0x61, + 0x73, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x72, 0x65, 0x73, 0x65, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x52, 0x65, 0x73, 0x65, 0x74, 0x22, 0x49, 0x0a, + 0x17, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, + 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, + 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, + 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x22, 0x36, 0x0a, 0x18, 0x47, 0x65, 0x6e, 0x65, + 0x72, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, + 0x22, 0x47, 0x0a, 0x13, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, + 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x31, 0x0a, 0x15, 0x55, 0x6e, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x30, 0x0a, 0x14, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x74, + 0x0a, 0x16, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x54, 0x50, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x22, 0x8f, 0x03, 0x0a, 0x13, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x36, 0x0a, 0x04, 0x70, 0x61, - 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, - 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6d, 0x63, 0x75, 0x62, 0x65, 0x2e, 0x70, 0x61, 0x67, 0x65, - 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x70, 0x61, - 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, - 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x3e, - 0x0a, 0x09, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, - 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, - 0x54, 0x79, 0x70, 0x65, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x21, - 0x0a, 0x0c, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x49, - 0x64, 0x12, 0x27, 0x0a, 0x0f, 0x77, 0x69, 0x74, 0x68, 0x5f, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, - 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x77, 0x69, 0x74, 0x68, - 0x44, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x65, - 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0c, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, - 0x20, 0x0a, 0x0c, 0x77, 0x69, 0x74, 0x68, 0x5f, 0x61, 0x6c, 0x6c, 0x5f, 0x73, 0x75, 0x62, 0x18, - 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x77, 0x69, 0x74, 0x68, 0x41, 0x6c, 0x6c, 0x53, 0x75, - 0x62, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x6b, 0x69, 0x70, 0x5f, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, - 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x73, 0x6b, 0x69, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x73, - 0x12, 0x1a, 0x0a, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x73, 0x18, 0x09, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x73, 0x12, 0x16, 0x0a, 0x06, - 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, - 0x6d, 0x61, 0x69, 0x6e, 0x22, 0xd8, 0x01, 0x0a, 0x14, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x45, 0x0a, - 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0e, 0x32, 0x24, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, - 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x55, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x23, - 0x0a, 0x0d, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, - 0x74, 0x49, 0x64, 0x12, 0x3a, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, - 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x50, - 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x22, - 0x82, 0x01, 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, - 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x6c, 0x64, 0x50, 0x61, 0x73, 0x73, 0x12, 0x19, - 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x6e, 0x65, 0x77, 0x50, 0x61, 0x73, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, - 0x72, 0x65, 0x73, 0x65, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x52, - 0x65, 0x73, 0x65, 0x74, 0x22, 0x49, 0x0a, 0x17, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, - 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, - 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x22, - 0x36, 0x0a, 0x18, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, - 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, - 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, - 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x47, 0x0a, 0x13, 0x42, 0x6c, 0x6f, 0x63, 0x6b, - 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, - 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, - 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, - 0x22, 0x31, 0x0a, 0x15, 0x55, 0x6e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x22, 0x30, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, - 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x74, 0x12, 0x40, 0x0a, 0x0a, 0x6f, 0x74, 0x70, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, + 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, + 0x4f, 0x54, 0x50, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x09, 0x6f, 0x74, 0x70, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, + 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1037,7 +1129,7 @@ func file_apps_user_pb_request_proto_rawDescGZIP() []byte { return file_apps_user_pb_request_proto_rawDescData } -var file_apps_user_pb_request_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_apps_user_pb_request_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_apps_user_pb_request_proto_goTypes = []interface{}{ (*Profile)(nil), // 0: infraboard.keyauth.user.Profile (*CreateAccountRequest)(nil), // 1: infraboard.keyauth.user.CreateAccountRequest @@ -1050,26 +1142,29 @@ var file_apps_user_pb_request_proto_goTypes = []interface{}{ (*BlockAccountRequest)(nil), // 8: infraboard.keyauth.user.BlockAccountRequest (*UnBlockAccountRequest)(nil), // 9: infraboard.keyauth.user.UnBlockAccountRequest (*DeleteAccountRequest)(nil), // 10: infraboard.keyauth.user.DeleteAccountRequest - (Gender)(0), // 11: infraboard.keyauth.user.Gender - (CreateType)(0), // 12: infraboard.keyauth.user.CreateType - (types.UserType)(0), // 13: infraboard.keyauth.user.UserType - (*request.PageRequest)(nil), // 14: infraboard.mcube.page.PageRequest - (types1.UpdateMode)(0), // 15: infraboard.keyauth.types.UpdateMode + (*UpdateOTPStatusRequest)(nil), // 11: infraboard.keyauth.user.UpdateOTPStatusRequest + (Gender)(0), // 12: infraboard.keyauth.user.Gender + (CreateType)(0), // 13: infraboard.keyauth.user.CreateType + (types.UserType)(0), // 14: infraboard.keyauth.user.UserType + (*request.PageRequest)(nil), // 15: infraboard.mcube.page.PageRequest + (types1.UpdateMode)(0), // 16: infraboard.keyauth.types.UpdateMode + (otp.OTPStatus)(0), // 17: infraboard.keyauth.otp.OTPStatus } var file_apps_user_pb_request_proto_depIdxs = []int32{ - 11, // 0: infraboard.keyauth.user.Profile.gender:type_name -> infraboard.keyauth.user.Gender - 12, // 1: infraboard.keyauth.user.CreateAccountRequest.create_type:type_name -> infraboard.keyauth.user.CreateType - 13, // 2: infraboard.keyauth.user.CreateAccountRequest.user_type:type_name -> infraboard.keyauth.user.UserType + 12, // 0: infraboard.keyauth.user.Profile.gender:type_name -> infraboard.keyauth.user.Gender + 13, // 1: infraboard.keyauth.user.CreateAccountRequest.create_type:type_name -> infraboard.keyauth.user.CreateType + 14, // 2: infraboard.keyauth.user.CreateAccountRequest.user_type:type_name -> infraboard.keyauth.user.UserType 0, // 3: infraboard.keyauth.user.CreateAccountRequest.profile:type_name -> infraboard.keyauth.user.Profile - 14, // 4: infraboard.keyauth.user.QueryAccountRequest.page:type_name -> infraboard.mcube.page.PageRequest - 13, // 5: infraboard.keyauth.user.QueryAccountRequest.user_type:type_name -> infraboard.keyauth.user.UserType - 15, // 6: infraboard.keyauth.user.UpdateAccountRequest.update_mode:type_name -> infraboard.keyauth.types.UpdateMode + 15, // 4: infraboard.keyauth.user.QueryAccountRequest.page:type_name -> infraboard.mcube.page.PageRequest + 14, // 5: infraboard.keyauth.user.QueryAccountRequest.user_type:type_name -> infraboard.keyauth.user.UserType + 16, // 6: infraboard.keyauth.user.UpdateAccountRequest.update_mode:type_name -> infraboard.keyauth.types.UpdateMode 0, // 7: infraboard.keyauth.user.UpdateAccountRequest.profile:type_name -> infraboard.keyauth.user.Profile - 8, // [8:8] is the sub-list for method output_type - 8, // [8:8] is the sub-list for method input_type - 8, // [8:8] is the sub-list for extension type_name - 8, // [8:8] is the sub-list for extension extendee - 0, // [0:8] is the sub-list for field type_name + 17, // 8: infraboard.keyauth.user.UpdateOTPStatusRequest.otp_status:type_name -> infraboard.keyauth.otp.OTPStatus + 9, // [9:9] is the sub-list for method output_type + 9, // [9:9] is the sub-list for method input_type + 9, // [9:9] is the sub-list for extension type_name + 9, // [9:9] is the sub-list for extension extendee + 0, // [0:9] is the sub-list for field type_name } func init() { file_apps_user_pb_request_proto_init() } @@ -1211,6 +1306,18 @@ func file_apps_user_pb_request_proto_init() { return nil } } + file_apps_user_pb_request_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateOTPStatusRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1218,7 +1325,7 @@ func file_apps_user_pb_request_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_apps_user_pb_request_proto_rawDesc, NumEnums: 0, - NumMessages: 11, + NumMessages: 12, NumExtensions: 0, NumServices: 0, }, diff --git a/apps/user/request_ext.go b/apps/user/request_ext.go index ad69f285..5aa22697 100644 --- a/apps/user/request_ext.go +++ b/apps/user/request_ext.go @@ -74,6 +74,10 @@ func NewCreateUserRequestWithLDAPSync(username, password string) *CreateAccountR return req } +func CreateAccountRequestEnableOTP(req *CreateAccountRequest) { + req.OtpEnabled = true +} + // NewCreateUserRequestWithWXWORKSync todo func NewCreateUserRequestWithWXWORKSync(username, password string) *CreateAccountRequest { req := NewCreateUserRequest() @@ -156,3 +160,11 @@ func (req *UnBlockAccountRequest) Validate() error { return nil } + +func NewUpdateOTPStatusRequest() *UpdateOTPStatusRequest { + return &UpdateOTPStatusRequest{} +} + +func (req *UpdateOTPStatusRequest) Validate() error { + return validate.Struct(req) +} diff --git a/apps/user/service.pb.go b/apps/user/service.pb.go index 4a64650f..64af3486 100644 --- a/apps/user/service.pb.go +++ b/apps/user/service.pb.go @@ -28,7 +28,7 @@ var file_apps_user_pb_service_proto_rawDesc = []byte{ 0x2e, 0x75, 0x73, 0x65, 0x72, 0x1a, 0x1a, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x2f, - 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x8f, 0x07, 0x0a, 0x07, 0x53, + 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xf2, 0x07, 0x0a, 0x07, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5a, 0x0a, 0x0c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x2c, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, @@ -85,10 +85,17 @@ var file_apps_user_pb_service_proto_rawDesc = []byte{ 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x31, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x50, 0x61, 0x73, 0x73, - 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x29, 0x5a, 0x27, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, - 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, - 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x61, 0x0a, 0x0f, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x54, 0x50, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x2f, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, + 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x4f, 0x54, 0x50, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1d, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, + 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x42, + 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, + 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, + 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var file_apps_user_pb_service_proto_goTypes = []interface{}{ @@ -101,10 +108,11 @@ var file_apps_user_pb_service_proto_goTypes = []interface{}{ (*UpdateAccountRequest)(nil), // 6: infraboard.keyauth.user.UpdateAccountRequest (*UpdatePasswordRequest)(nil), // 7: infraboard.keyauth.user.UpdatePasswordRequest (*GeneratePasswordRequest)(nil), // 8: infraboard.keyauth.user.GeneratePasswordRequest - (*Set)(nil), // 9: infraboard.keyauth.user.Set - (*User)(nil), // 10: infraboard.keyauth.user.User - (*Password)(nil), // 11: infraboard.keyauth.user.Password - (*GeneratePasswordResponse)(nil), // 12: infraboard.keyauth.user.GeneratePasswordResponse + (*UpdateOTPStatusRequest)(nil), // 9: infraboard.keyauth.user.UpdateOTPStatusRequest + (*Set)(nil), // 10: infraboard.keyauth.user.Set + (*User)(nil), // 11: infraboard.keyauth.user.User + (*Password)(nil), // 12: infraboard.keyauth.user.Password + (*GeneratePasswordResponse)(nil), // 13: infraboard.keyauth.user.GeneratePasswordResponse } var file_apps_user_pb_service_proto_depIdxs = []int32{ 0, // 0: infraboard.keyauth.user.Service.QueryAccount:input_type -> infraboard.keyauth.user.QueryAccountRequest @@ -116,17 +124,19 @@ var file_apps_user_pb_service_proto_depIdxs = []int32{ 6, // 6: infraboard.keyauth.user.Service.UpdateAccountProfile:input_type -> infraboard.keyauth.user.UpdateAccountRequest 7, // 7: infraboard.keyauth.user.Service.UpdateAccountPassword:input_type -> infraboard.keyauth.user.UpdatePasswordRequest 8, // 8: infraboard.keyauth.user.Service.GeneratePassword:input_type -> infraboard.keyauth.user.GeneratePasswordRequest - 9, // 9: infraboard.keyauth.user.Service.QueryAccount:output_type -> infraboard.keyauth.user.Set - 10, // 10: infraboard.keyauth.user.Service.DescribeAccount:output_type -> infraboard.keyauth.user.User - 10, // 11: infraboard.keyauth.user.Service.CreateAccount:output_type -> infraboard.keyauth.user.User - 10, // 12: infraboard.keyauth.user.Service.BlockAccount:output_type -> infraboard.keyauth.user.User - 10, // 13: infraboard.keyauth.user.Service.UnBlockAccount:output_type -> infraboard.keyauth.user.User - 10, // 14: infraboard.keyauth.user.Service.DeleteAccount:output_type -> infraboard.keyauth.user.User - 10, // 15: infraboard.keyauth.user.Service.UpdateAccountProfile:output_type -> infraboard.keyauth.user.User - 11, // 16: infraboard.keyauth.user.Service.UpdateAccountPassword:output_type -> infraboard.keyauth.user.Password - 12, // 17: infraboard.keyauth.user.Service.GeneratePassword:output_type -> infraboard.keyauth.user.GeneratePasswordResponse - 9, // [9:18] is the sub-list for method output_type - 0, // [0:9] is the sub-list for method input_type + 9, // 9: infraboard.keyauth.user.Service.UpdateOTPStatus:input_type -> infraboard.keyauth.user.UpdateOTPStatusRequest + 10, // 10: infraboard.keyauth.user.Service.QueryAccount:output_type -> infraboard.keyauth.user.Set + 11, // 11: infraboard.keyauth.user.Service.DescribeAccount:output_type -> infraboard.keyauth.user.User + 11, // 12: infraboard.keyauth.user.Service.CreateAccount:output_type -> infraboard.keyauth.user.User + 11, // 13: infraboard.keyauth.user.Service.BlockAccount:output_type -> infraboard.keyauth.user.User + 11, // 14: infraboard.keyauth.user.Service.UnBlockAccount:output_type -> infraboard.keyauth.user.User + 11, // 15: infraboard.keyauth.user.Service.DeleteAccount:output_type -> infraboard.keyauth.user.User + 11, // 16: infraboard.keyauth.user.Service.UpdateAccountProfile:output_type -> infraboard.keyauth.user.User + 12, // 17: infraboard.keyauth.user.Service.UpdateAccountPassword:output_type -> infraboard.keyauth.user.Password + 13, // 18: infraboard.keyauth.user.Service.GeneratePassword:output_type -> infraboard.keyauth.user.GeneratePasswordResponse + 11, // 19: infraboard.keyauth.user.Service.UpdateOTPStatus:output_type -> infraboard.keyauth.user.User + 10, // [10:20] is the sub-list for method output_type + 0, // [0:10] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name diff --git a/apps/user/service_grpc.pb.go b/apps/user/service_grpc.pb.go index 9df05b6d..951ae1ef 100644 --- a/apps/user/service_grpc.pb.go +++ b/apps/user/service_grpc.pb.go @@ -40,6 +40,8 @@ type ServiceClient interface { UpdateAccountPassword(ctx context.Context, in *UpdatePasswordRequest, opts ...grpc.CallOption) (*Password, error) // GeneratePassword 生成符合检测强度的随机密码 GeneratePassword(ctx context.Context, in *GeneratePasswordRequest, opts ...grpc.CallOption) (*GeneratePasswordResponse, error) + // 开启或关闭OTP + UpdateOTPStatus(ctx context.Context, in *UpdateOTPStatusRequest, opts ...grpc.CallOption) (*User, error) } type serviceClient struct { @@ -131,6 +133,15 @@ func (c *serviceClient) GeneratePassword(ctx context.Context, in *GeneratePasswo return out, nil } +func (c *serviceClient) UpdateOTPStatus(ctx context.Context, in *UpdateOTPStatusRequest, opts ...grpc.CallOption) (*User, error) { + out := new(User) + err := c.cc.Invoke(ctx, "/infraboard.keyauth.user.Service/UpdateOTPStatus", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // ServiceServer is the server API for Service service. // All implementations must embed UnimplementedServiceServer // for forward compatibility @@ -153,6 +164,8 @@ type ServiceServer interface { UpdateAccountPassword(context.Context, *UpdatePasswordRequest) (*Password, error) // GeneratePassword 生成符合检测强度的随机密码 GeneratePassword(context.Context, *GeneratePasswordRequest) (*GeneratePasswordResponse, error) + // 开启或关闭OTP + UpdateOTPStatus(context.Context, *UpdateOTPStatusRequest) (*User, error) mustEmbedUnimplementedServiceServer() } @@ -187,6 +200,9 @@ func (UnimplementedServiceServer) UpdateAccountPassword(context.Context, *Update func (UnimplementedServiceServer) GeneratePassword(context.Context, *GeneratePasswordRequest) (*GeneratePasswordResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GeneratePassword not implemented") } +func (UnimplementedServiceServer) UpdateOTPStatus(context.Context, *UpdateOTPStatusRequest) (*User, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateOTPStatus not implemented") +} func (UnimplementedServiceServer) mustEmbedUnimplementedServiceServer() {} // UnsafeServiceServer may be embedded to opt out of forward compatibility for this service. @@ -362,6 +378,24 @@ func _Service_GeneratePassword_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _Service_UpdateOTPStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateOTPStatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).UpdateOTPStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/infraboard.keyauth.user.Service/UpdateOTPStatus", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).UpdateOTPStatus(ctx, req.(*UpdateOTPStatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Service_ServiceDesc is the grpc.ServiceDesc for Service service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -405,6 +439,10 @@ var Service_ServiceDesc = grpc.ServiceDesc{ MethodName: "GeneratePassword", Handler: _Service_GeneratePassword_Handler, }, + { + MethodName: "UpdateOTPStatus", + Handler: _Service_UpdateOTPStatus_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "apps/user/pb/service.proto", diff --git a/apps/user/user.pb.go b/apps/user/user.pb.go index ea33dd37..2abf6e0c 100644 --- a/apps/user/user.pb.go +++ b/apps/user/user.pb.go @@ -8,6 +8,7 @@ package user import ( department "github.com/infraboard/keyauth/apps/department" + otp "github.com/infraboard/keyauth/apps/otp" types "github.com/infraboard/keyauth/apps/user/types" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -262,6 +263,9 @@ type User struct { // 部门 // @gotags: bson:"-" json:"department,omitempty" Department *department.Department `protobuf:"bytes,15,opt,name=department,proto3" json:"department,omitempty" bson:"-"` + // 动态令牌是否开启 + // @gotags: bson:"otp_enabled" json:"otp_enabled,omitempty" + OtpStatus otp.OTPStatus `protobuf:"varint,16,opt,name=otp_status,json=otpStatus,proto3,enum=infraboard.keyauth.otp.OTPStatus" json:"otp_enabled,omitempty" bson:"otp_enabled"` } func (x *User) Reset() { @@ -401,6 +405,13 @@ func (x *User) GetDepartment() *department.Department { return nil } +func (x *User) GetOtpStatus() otp.OTPStatus { + if x != nil { + return x.OtpStatus + } + return otp.OTPStatus(0) +} + type Set struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -471,80 +482,85 @@ var file_apps_user_pb_user_proto_rawDesc = []byte{ 0x6f, 0x1a, 0x1a, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x2f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x2f, 0x65, 0x6e, 0x75, 0x6d, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdb, 0x01, 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, - 0x6f, 0x72, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, - 0x1b, 0x0a, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1b, 0x0a, 0x09, - 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x08, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x65, 0x65, - 0x64, 0x5f, 0x72, 0x65, 0x73, 0x65, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6e, - 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x65, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x73, 0x65, - 0x74, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, - 0x72, 0x65, 0x73, 0x65, 0x74, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x68, - 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x68, 0x69, - 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x65, 0x78, 0x70, 0x69, - 0x72, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x45, 0x78, 0x70, - 0x69, 0x72, 0x65, 0x64, 0x22, 0x85, 0x01, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, - 0x16, 0x0a, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x65, - 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x6c, 0x6f, - 0x63, 0x6b, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6c, 0x6f, 0x63, 0x6b, - 0x65, 0x64, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, - 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x52, 0x65, 0x73, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x75, - 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, - 0x52, 0x0a, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xa2, 0x05, 0x0a, - 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, - 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x65, - 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x44, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, - 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, - 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, - 0x73, 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, - 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x63, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x75, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x41, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x35, 0x0a, 0x04, - 0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, - 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, - 0x79, 0x70, 0x65, 0x12, 0x3a, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x08, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, - 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x50, - 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, - 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, - 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, - 0x5f, 0x64, 0x61, 0x79, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x65, 0x78, 0x70, - 0x69, 0x72, 0x65, 0x73, 0x44, 0x61, 0x79, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, - 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, - 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x69, 0x73, - 0x5f, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x18, 0x0c, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x0d, 0x69, 0x73, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, - 0x64, 0x12, 0x4a, 0x0a, 0x0f, 0x68, 0x61, 0x73, 0x68, 0x65, 0x64, 0x5f, 0x70, 0x61, 0x73, 0x73, - 0x77, 0x6f, 0x72, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, - 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x2e, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x0e, 0x68, - 0x61, 0x73, 0x68, 0x65, 0x64, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x37, 0x0a, - 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, - 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, - 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, - 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x49, 0x0a, 0x0a, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, - 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x69, 0x6e, 0x66, - 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, - 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x44, 0x65, 0x70, 0x61, 0x72, - 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, - 0x74, 0x22, 0x50, 0x0a, 0x03, 0x53, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, - 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x12, 0x33, - 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, - 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, - 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x69, 0x74, - 0x65, 0x6d, 0x73, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, - 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x15, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x6f, 0x74, 0x70, + 0x2f, 0x70, 0x62, 0x2f, 0x6f, 0x74, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdb, 0x01, + 0x0a, 0x08, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, + 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, + 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x41, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x74, + 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x65, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x73, 0x65, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6e, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x65, 0x74, 0x12, + 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x73, 0x65, 0x74, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x65, 0x74, 0x52, 0x65, 0x61, 0x73, + 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x06, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x07, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1d, 0x0a, 0x0a, + 0x69, 0x73, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x09, 0x69, 0x73, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x64, 0x22, 0x85, 0x01, 0x0a, 0x06, + 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x12, 0x1f, + 0x0a, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x0a, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, + 0x21, 0x0a, 0x0c, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x6e, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x52, 0x65, 0x73, + 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x69, 0x6d, + 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x75, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x54, + 0x69, 0x6d, 0x65, 0x22, 0xe4, 0x05, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x23, 0x0a, 0x0d, + 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x49, + 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x44, 0x0a, 0x0b, 0x63, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x23, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, + 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1b, + 0x0a, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x03, 0x52, 0x08, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x64, + 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, + 0x61, 0x69, 0x6e, 0x12, 0x35, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, + 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, + 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x3a, 0x0a, 0x07, 0x70, 0x72, + 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x69, 0x6e, + 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, + 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x07, 0x70, + 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x18, + 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x12, 0x21, 0x0a, 0x0c, + 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, 0x64, 0x61, 0x79, 0x73, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x0b, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x44, 0x61, 0x79, 0x73, 0x12, + 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x0b, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x69, 0x73, 0x5f, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, + 0x7a, 0x65, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x69, 0x73, 0x49, 0x6e, 0x69, + 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x12, 0x4a, 0x0a, 0x0f, 0x68, 0x61, 0x73, 0x68, + 0x65, 0x64, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x21, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, + 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x50, 0x61, 0x73, 0x73, + 0x77, 0x6f, 0x72, 0x64, 0x52, 0x0e, 0x68, 0x61, 0x73, 0x68, 0x65, 0x64, 0x50, 0x61, 0x73, 0x73, + 0x77, 0x6f, 0x72, 0x64, 0x12, 0x37, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0e, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, + 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x49, 0x0a, + 0x0a, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x0f, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x29, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, + 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x64, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, + 0x74, 0x2e, 0x44, 0x65, 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, 0x64, 0x65, + 0x70, 0x61, 0x72, 0x74, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x40, 0x0a, 0x0a, 0x6f, 0x74, 0x70, 0x5f, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x69, + 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, + 0x68, 0x2e, 0x6f, 0x74, 0x70, 0x2e, 0x4f, 0x54, 0x50, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, + 0x09, 0x6f, 0x74, 0x70, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x50, 0x0a, 0x03, 0x53, 0x65, + 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x12, 0x33, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x62, 0x6f, + 0x61, 0x72, 0x64, 0x2e, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x75, 0x73, 0x65, 0x72, + 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x42, 0x29, 0x5a, 0x27, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, + 0x62, 0x6f, 0x61, 0x72, 0x64, 0x2f, 0x6b, 0x65, 0x79, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x61, 0x70, + 0x70, 0x73, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -569,6 +585,7 @@ var file_apps_user_pb_user_proto_goTypes = []interface{}{ (types.UserType)(0), // 5: infraboard.keyauth.user.UserType (*Profile)(nil), // 6: infraboard.keyauth.user.Profile (*department.Department)(nil), // 7: infraboard.keyauth.department.Department + (otp.OTPStatus)(0), // 8: infraboard.keyauth.otp.OTPStatus } var file_apps_user_pb_user_proto_depIdxs = []int32{ 4, // 0: infraboard.keyauth.user.User.create_type:type_name -> infraboard.keyauth.user.CreateType @@ -577,12 +594,13 @@ var file_apps_user_pb_user_proto_depIdxs = []int32{ 0, // 3: infraboard.keyauth.user.User.hashed_password:type_name -> infraboard.keyauth.user.Password 1, // 4: infraboard.keyauth.user.User.status:type_name -> infraboard.keyauth.user.Status 7, // 5: infraboard.keyauth.user.User.department:type_name -> infraboard.keyauth.department.Department - 2, // 6: infraboard.keyauth.user.Set.items:type_name -> infraboard.keyauth.user.User - 7, // [7:7] is the sub-list for method output_type - 7, // [7:7] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 8, // 6: infraboard.keyauth.user.User.otp_status:type_name -> infraboard.keyauth.otp.OTPStatus + 2, // 7: infraboard.keyauth.user.Set.items:type_name -> infraboard.keyauth.user.User + 8, // [8:8] is the sub-list for method output_type + 8, // [8:8] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_apps_user_pb_user_proto_init() } diff --git a/apps/user/user_ext.go b/apps/user/user_ext.go index 13553993..a4ef9486 100644 --- a/apps/user/user_ext.go +++ b/apps/user/user_ext.go @@ -54,6 +54,10 @@ func New(req *CreateAccountRequest) (*User, error) { u.IsInitialized = true } + // if req.OtpEnabled { + + // } + return u, nil } From cb56838e471579513c1389e3cab321b0d0522c96 Mon Sep 17 00:00:00 2001 From: lbzs <627062293@qq.com> Date: Thu, 21 Apr 2022 22:42:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0OTP=E5=8F=8C=E5=9B=A0?= =?UTF-8?q?=E7=B4=A0=E8=AE=A4=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/client.go b/client/client.go index 594880e3..76096f38 100644 --- a/client/client.go +++ b/client/client.go @@ -12,6 +12,7 @@ import ( "github.com/infraboard/keyauth/apps/mconf" "github.com/infraboard/keyauth/apps/micro" "github.com/infraboard/keyauth/apps/namespace" + "github.com/infraboard/keyauth/apps/otp" "github.com/infraboard/keyauth/apps/permission" "github.com/infraboard/keyauth/apps/policy" "github.com/infraboard/keyauth/apps/role" @@ -139,3 +140,8 @@ func (c *Client) User() user.ServiceClient { func (c *Client) Verifycode() verifycode.ServiceClient { return verifycode.NewServiceClient(c.conn) } + +// Otp todo +func (c *Client) Otp() otp.ServiceClient { + return otp.NewServiceClient(c.conn) +}