.NET Server integration

Hi! I’m new to Nakama so forgive me if this has been addressed somewhere else.

I have a Unity game with a .NET Core REST backend that will connect to Nakama. Ex:

Client => Backend (with nakama SDK) => Nakama

I am not finding a way to send the session to the client and then for the client to send it back to the Backend for calling rpcs.

I thought that serializing the session to send it as a string to the client and then deserializing it back will work, but Nakama.Session does not have a constructor.

var session = Task.Run(async () =>
            var session = await Client.AuthenticateDeviceAsync(deviceId);
            return session;
        return JsonConvert.SerializeObject(session);

And when I get a call from Unity:

var nakamaSession = JsonConvert.DeserializeObject<Nakama.Session>(session);
        var objects = Task.Run(async () =>
            return await Client.ReadStorageObjectsAsync(nakamaSession,
                new[] { new StorageObjectId() { Collection = collection, Key = key, UserId = nakamaSession.UserId } });

Nakama.Session does not have a constructor, so that fails.

Is there a way to achieve this? Is there a better patter for this kind of case?


Hi Matias!

Ive already tried in the beggining to do the same way as you, but after some research Ive found that is possible but will be a lot of headache to maintain and secure a connection like this.

The “nakama SDK” that you is referring is a Client SDK.
So it`s like: A Lot of Clients (Unity clients) => Client (.NET Core) => Nakama

If you want to a different backend to do other backend stuff will be easier to go on this configuration

Clients => Nakama => Backend (.Net Core)
with nk.httpRequest on the Nakama Server to access the .NET Core

Im working with this to access some wrappers and apis that is hard to achieve on the TS Server-Framework

1 Like

@novabyte I saw in this post: ASP .NET Core Server Integration

You encourage this architecture. How do you suggest handling the session?

@matiasvillanueva I haven’t looked at the other thread. It’s been quite a while since I helped with the other thread. You can use Session.Restore(..., ...) in the .NET client to restore a AuthToken and RefreshToken (JWTs) into an ISession type.