Third client query grpc endpoint

⬆️ Upgrade protobuf
This commit is contained in:
2025-02-02 21:03:58 +08:00
parent 7d1165b87b
commit 7dbb552dd2
12 changed files with 835 additions and 197 deletions

View File

@ -20,6 +20,7 @@ type App struct {
proto.UnimplementedRealmServiceServer
proto.UnimplementedAuditServiceServer
proto.UnimplementedNotifyServiceServer
proto.UnimplementedThirdClientServiceServer
health.UnimplementedHealthServer
srv *grpc.Server
@ -36,6 +37,7 @@ func NewServer() *App {
proto.RegisterNotifyServiceServer(server.srv, server)
proto.RegisterRealmServiceServer(server.srv, server)
proto.RegisterAuditServiceServer(server.srv, server)
proto.RegisterThirdClientServiceServer(server.srv, server)
health.RegisterHealthServer(server.srv, server)
reflection.Register(server.srv)

View File

@ -0,0 +1,31 @@
package grpc
import (
"context"
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
"git.solsynth.dev/hypernet/passport/pkg/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (v *App) GetThirdClient(ctx context.Context, request *proto.GetThirdClientRequest) (*proto.GetThirdClientResponse, error) {
var client models.ThirdClient
if err := database.C.Where("id = ?", request.ClientId).First(&client).Error; err != nil {
return nil, status.Errorf(codes.NotFound, "requested client with id %d was not found", request.ClientId)
}
if request.Secret != nil {
if client.Secret != request.GetSecret() {
return nil, status.Errorf(codes.PermissionDenied, "invalid secret")
}
}
return &proto.GetThirdClientResponse{
Info: &proto.ThirdClientInfo{
Id: uint64(client.ID),
Name: client.Name,
Description: client.Description,
},
}, nil
}