Log in as System User

Hey there, I am working on a content authoring tool that will be used to upload data to our Nakama server. This toolset is being built within the Unity Editor, with none of the code being compiled to any client. What I am hoping to be able to accomplish is allowing the Editor to effectively log in as the system user so I can upload data that will be globally accessible. Is this something that is possible? I know I could use runtime code written in Lua to write storage objects but that would be less ideal.

Thanks for the help!

Hi @BergerBytes. There’s three ways to solve this use case that I can think of:

  1. I think you might be able to authenticate as the system user like any other user in Nakama but to do so you’d have to build the authentication token (JWT) directly with the same signing key that Nakama uses internally. This value is set with the command line flag --server.encryption_key.

  2. Setup a collection of RPC functions which you authenticate with the server against as a server to server RPC call. These functions can power your UI and you can use the regular Unity client sdk to make requests.

  3. Use the devconsole REST API to authenticate and query aspects of the system via the same API our Developer Console uses. You can see the Swagger spec for the REST API definitions here. You would authenticate with the console credentials over basic auth to get a session token and use that to interact with the API. We have APIs already to update storage objects and import many new objects in one go.

I think of these three options I’d suggest option 3 the most followed by option 2 which might be easier to setup quickly.

Hey there, I am working on a content authoring tool that will be used to upload data to our Nakama server. This toolset is being built within the Unity Editor, with none of the code being compiled to any client.

This approach would have more domain specific advantages (i.e. you can structure the format to upload into the storage engine to be specific to the structure of your game) but have you considered just using the import option from within the Developer Console UI?

Hey @novabyte, Thank you for the response! I will definitely take a look at the offered solutions and see which will be the best solution.

As for why I was trying to avoid using the Developer Console UI; In looking for a backend solution I tried some more “Turn-Key” solutions that, while ultimately left me wanting, had some helpful Admin APIs exposed in the editor that I was using in the prototype for the tool I am building. But you make a great point, other than the loss of convenience, I can accomplish everything I need to by exporting the objects to JSON files and manually uploading them.

1 Like

Ok great. This is the format you should use to structure your import file for it to be accepted through the Developer Console.

[{
    "collection": "testcollection",
    "key": "testkey",
    "user_id": "fb912423-82cb-4e3a-8f67-42c37be19a3c",
    "value": "{\"hello\": \"world\"}",
    "permission_read": 2,
    "permission_write": 1
}, {
    "collection": "testcollection",
    "key": "testkey2",
    "user_id": "9e997e08-7e81-4d3b-a3d3-3458f7c5e5e1",
    "value": "{\"hello\": \"world\"}",
    "permission_read": 1,
    "permission_write": 1
}]

The rules of the storage engine are described here.

Also please open new feature requests for improvements you’d like to see that make the server APIs more flexible. :+1: