Issue
You may encounter the following error message when attempting anonymous sign-in using Unity Authentication:
"Token has expired."
While this error typically indicates that the authentication token’s validity period has ended, there is a common but often overlooked cause that can trigger this error even if the token itself is still valid.
Cause
A frequent but less-known cause of the "Token has expired." error is an incorrect system clock on the device running the application. Unity’s Authentication system validates tokens against the device’s local time. If the device’s clock is significantly out of sync—due to manual changes, incorrect time zone settings, or system bugs—it can cause valid tokens to appear expired, resulting in this error.
Solution
To resolve this error, verify and correct the system time on the device running the game or application. Ensure the device’s clock:
-
Is set to the correct date and time
-
Is synchronized with an internet time server (if possible)
-
Has the correct time zone configured
After correcting the system clock, restart the application and try signing in anonymously again. This should resolve the token expiry issue.
Additional Recommendations
-
If your application stores authentication tokens locally (e.g., PlayerPrefs), consider clearing them during troubleshooting to avoid corrupted or stale tokens causing repeated failures.
-
Ensure you have called
await UnityServices.InitializeAsync()before attempting to sign in anonymously, as initialization is required to properly set up authentication services. -
Confirm that the Authentication package is correctly installed via the Package Manager and that your project is linked to the Unity Dashboard.
-
Always sign in as early as possible in your app lifecycle (e.g., during
AwakeorStart) to prevent token errors when calling dependent Unity Services.
If you continue to experience issues after verifying your system clock and following these steps, please reach out to Unity Support for further help.