Skip to main content

User Login & Authentication

Last updated: 16 July 2026

PlayServ assumes the client performs user authentication in an external system — your identity provider — and then passes the resulting UserToken into the SDK. PlayServ uses that token to upgrade the session privileges and bind the session to an existing user profile, or create a new one.

info

Use this flow when:

  • the player has just completed authentication in your UI — username/password, provider sign-in, etc.
  • the app starts and you already have a previously stored UserToken
  • you need to re-authenticate because the token is no longer valid

The login flow

1

Authenticate the player in your external system

The player signs in through your identity provider — username/password, a social provider, or any other method you support. On success, your system issues a UserToken.

PlayServ does not perform this step itself; it consumes the token your system produces.

2

Pass the UserToken into the SDK

Hand the UserToken to the SDK so PlayServ can upgrade the session. There are two entry points depending on when you have the token — Ready(UserToken) at session start, or Login(UserToken) during runtime. Both perform the same privilege upgrade. See Ready and Login below.

3

PlayServ validates and upgrades the session

During the handshake PlayServ calls ValidateClient on the server (if declared). If validation passes, the session privileges are upgraded and the session is bound to the player's profile. If it fails, the client is denied.


Ready and Login: two entry points

Ready(UserToken) and Login(UserToken) perform the same privilege upgrade — the difference is timing.

If the user was authenticated earlier and the UserToken is already stored locally, pass it immediately when starting the session:

await PlayServ.Ready(UserToken);

Because the upgrade happens at session start, the authenticated state is reached sooner than calling Login(...) afterwards.


When the token is no longer valid

If the player session ends or the stored token becomes invalid, the handshake may return an error on Ready(UserToken). In that case:

1

Re-authenticate externally

The player authenticates again in your external system, which issues a fresh UserToken.

2

Call Login with the new token

Pass the newly issued token with Login(UserToken) to upgrade the session again.


Server-side validation: ValidateClient

To validate the authenticated client on the server, PlayServ performs an RPC call to ValidateClient, if it is declared in server code. Return true to accept the client, or false to deny it — if validation fails, the client does not receive the privilege upgrade and is disconnected.

[Server]
public class ClientAuth
{
public bool ValidateClient(Session session)
{
// return true -> validation passed, privileges upgraded
// return false -> client denied / disconnected
return true;
}
}
warning

ValidateClient is the enforcement point for UserToken validity. Treat this method as your server-side gate for upgrading privileges.


How this relates to handshake and session

  • Ready(UserToken) affects the handshake path at session start.
  • Login(UserToken) is the same privilege upgrade, but initiated later during runtime.
  • Session state remains the primary indicator for the client's runtime readiness.

Next steps