How to Authenticate my Server?

I’ve tried implementing Economy in my game, but I’m confused about the services.

Why can the client write to currencies directly?

I set up a Cloud Code Script to handle access from the Game Server, but it says I don’t have permission to write to another player’s Economy Currency value.
I guess because the Server has no special Auth.

Is there a way to authenticate the server for this permission?

await ServerAuthenticationService.Instance.SignInFromServerAsync();
var token = ServerAuthenticationService.Instance.AccessToken;

ServerAuthenticationService doesnt exist in my Unity.Services.Authentication
package.

Am I missing something? It feels like I’m using these services wrong since everything seems centered around the local player.

Edit:

I had use
const currencies = new CurrenciesApi(context);
instead of
const currencies = new CurrenciesApi({ accessToken });

But my Question still persists, do these Enpoints need some kind of Auth for safety?

Hey! Check this out: Interact with cross-player data

Let me know if this solves your case

1 Like

What Marius pointed out should allow you to write to other players.

As a player, you’re only allowed to read/write your own data

As a service, (through cloud-code or a dedicated server auth), you can r/w any player data (which is what Marius pointed out).
To remove the rights for a player auth to write, you can set that up with an Access Control config: Access control

await ServerAuthenticationService.Instance.SignInFromServerAsync();
var token = ServerAuthenticationService.Instance.AccessToken;

This snippet of code is to authenticate a dedicated server to use service auth.
Not all packages support service auth, but the APIS package does: Redirecting to latest version of com.unity.services.apis

Let me know if you need more information.
Gab