Files
rudder-unity-sdk/skills/rudder-unity-sdk/reference/authentication.md
T
edmand46 22805173eb
CI / check (push) Successful in 6s
CI / publish (push) Has been skipped
Add agent skill (SKILL.md + per-domain reference)
2026-08-29 11:46:25 +03:00

1.9 KiB

Authentication and player profile

Namespace RudderSdk.Core. Verified against the bundled Rudder.Core.dll and Samples~/Authentication/AuthenticationSample.cs.

Sign in

var client = Rudder.Initialize();
await client.AuthorizeWithDeviceAsync("global", "en", nickname: "Player");

RudderClient.AuthorizeWithDeviceAsync(string region, string language, string nickname = null, CancellationToken cancellationToken = default) returns LoginViaDeviceResponse (AccessToken, RefreshToken). It performs device login and then restores persisted scenario runs. Tokens are saved to PlayerPrefs by the Unity adapter.

Lower-level alternative on client.Auth (login only, no scenario restore):

  • Task<LoginViaDeviceResponse> LoginWithDeviceAsync(string region, string language, string nickname = null, CancellationToken = default)
  • Task<bool> RefreshAsync() — explicit token refresh.
  • void Logout() — clears tokens locally.
  • event Action<RudderAuthState> AuthStateChangedRudderAuthState.SignedIn / SignedOut. SignedOut also fires when a refresh fails.

Login uses the SDK device id from PlayerPrefs. Do not pass SystemInfo.deviceUniqueIdentifier.

Profile and wallets

var profile = await client.Player.GetProfileAsync();
var nickname = profile.Player.Nickname;
foreach (var wallet in profile.Wallets)
    Debug.Log($"{wallet.Currency}: {wallet.Balance}");
  • Task<PlayerProfile> PlayerService.GetProfileAsync(CancellationToken = default)
  • PlayerProfilePlayer Player, List<Wallet> Wallets.
  • PlayerId, ProjectId, Nickname, Region, Language, CreatedAt (DateTimeOffset?).
  • WalletCurrency (string), Balance (long?).

Models are nullable since 0.4.0 — check fields before use. After any purchase or reward grant, reload the profile to see new wallet balances; there is no change callback.