Hello All,
I have two django applications and I want to send a user object from one django application to other django application through gRPC. I have seen string and integer types working fine. Please find the code attached.
service Usermanagement {
rpc UserLogin (UserRequest) returns (UserResponse) {}
}
// The request message containing the user's name.
message UserRequest {
string username = 1;
string password = 2;
}
// The response message containing the greetings
message UserResponse {
string message = 1;
string fullname = 2;
string token = 4;
int32 status = 5;
}
This is my Django application code.
import grpc
from userservice import userservices_pb2
from userservice import userservices_pb2_grpc
from usermanagement.models import AppUser as User
from django.contrib.auth import authenticate
from rest_framework.authtoken.models import Token
from google.protobuf import any_pb2
class Usermanagement(userservices_pb2_grpc.UsermanagementServicer):
def UserLogin(self, request, context):
User = authenticate(username=request.username, password=request.password)
if User is not None:
(token, created) = Token.objects.get_or_create(user=User)
User.authentication_token = token.key
return userservices_pb2.UserResponse(message='success', status=0, fullname=User.fullname, token = token.key)
else:
return userservices_pb2.UserResponse(message='Incorrect Username/Password', status=1)
Please anyone can help me "How can I include the User object or user list" in the return response.