Info
Usage
ClientAuthService - users
LoginClientAsync(email, password)
AnonymousLoginClientAsync() - per install token, no account needed. Used by default at start until the user logs out (AnonymousLoginByDefault, LoggedOutByUser)
RequestDeviceCodeAsync(), PollDeviceCodeAsync(deviceSecret) - sign in with a code the user approves on the website. Pending, denied and expired come back as ApiStatus 33-35
LogoutClientAsync()
CheckClientAuthAsync() - validates the stored token
RequestLinkCodeAsync(), GetLinkCodeStatusAsync() - link an anonymous account on the website, see Sign-in & Sessions
UserInfoChanged - user info changed (e.g. after linking)
SessionEnded(status) - session ended by the server, e.g. signed out on the Profile or banned. SessionEndReason keeps it until the next login
SignInAnswered(LoginResponse) - every sign-in answer, refreshes too, with what's pending: terms (Legal) and usage data sharing and studies (Analytics)
Prompts - what the app asks after a sign-in, see below
TryGetAuthUserInfo(out AuthUserInfo), static GetUserId()
ServerAuthService - dedicated servers
LoginServerAsync(serverId, secret)
PrepareServerAuthAsync, CheckServerAuthAsync, LogoutServerAsync
- Events on both
OnLoginSucceeded
OnLoginFailed(code, message)
OnLoggingOutAsync - awaited before logout, used to flush save data
OnLoggedOut
IsLoggedIn property
- UI
AuthLoginPanel - email / password, anonymous and provider login, one localized message per error (invalid credentials, banned, too many attempts with a cooldown, unreachable, account linked meanwhile, email not confirmed, signed out)
LoginProviderButton - one per provider, shown only when the provider is in ServiceHubSettings Login Providers (GoogleLoginProvider, MetaLoginProvider, AppleLoginProvider). The sign-in itself is not implemented yet
DeviceCodePanel - shows the code and URL, polls until approved
AccountLinkPanel - shows the link code and URL, waits until the account is linked
AuthPanelController - logged in toggle state and logout, optional confirm dialog
- Kit prefabs
Multiplayer/ServiceHub/AccountWindow, LoginProviderButton
ServiceHubUserDisplay - shows the user
LoggedInCondition - condition for UI and logic
- PurrNet:
ServiceHubAuthenticator sends the user id and a hashed install cookie, so a player keeps the same PlayerID on reconnect
After sign-in
SignInPrompts (ClientAuth.Prompts) - runs the ISignInPrompts one at a time by Order, after each login and once when the app starts signed in, so dialogs never stack. Background refreshes don't start them. A prompt can sign the player out, the rest then waits for the next sign-in
ASignInPrompt - a prompt placed in a scene or prefab, it joins once the hub is there. On the kit main menu: TermsPrompt (0, see Legal), UsageDataPrompt (10) and StudyPrompt (20, see Analytics)
SignInPromptScreen - the screen the prompts open on, placed with it (the main menu)
Example
var auth = AppCore.Services.Get<ServiceHubManager>().ClientAuth;
await auth.LoginClientAsync(_email.text, _password.text);
Gotchas
- Tokens are stored in
PlayerPrefs (AuthStorage.Client / AuthStorage.Server) and never logged. Polis/Local Data/Clear ServiceHub Logins (outside play mode) clears the editor's client and server logins
- At start the stored login is checked in the background, the app load doesn't wait for it and requests meanwhile use the stored session. A user who logged out stays logged out, no anonymous sign-in
- Client logins use a refresh token. The access token is refreshed automatically before it expires,
AuthStorage.SendAsync refreshes and retries once on 401. The refresh sends the app secret too, so after the secret is regenerated a build with the new one keeps its session