SDKs for Unity / Authentication via application launcher
  Back to Docs

SDKs for Unity

Authentication via application launcher

If you use Xsolla Launcher or Steam to deliver your application to users, you can automatically authenticate the user using the launcher’s credentials.

How-tos

Learn about advanced setups from our how-tos.

How to set up authentication in application via Launcher

You can use Xsolla Launcher to deliver your application to users and update it. The Launcher contains a built-in authorization tool. To avoid re-entering the username and password, set up authorization in your application via the Launcher.

Notice

To use the Launcher, you need to configure Login. Using a different authorization system is not supported.

The SDK uses the IGS & BB API to work with the store. The Launcher uses its own API, so the SDK doesn’t support working with the Launcher store.

To set up end-to-end user authentication:
  1. Implement the Launcher authorization logic in your application.
  2. Create an application build and upload it to the Launcher.
Note
Detailed information about Launcher settings and uploading the application build is provided in the integration guide.

Implement logic for authentication via Launcher

The flow for authorization in the application via Launcher is as follows:

  1. The user is authorized in Launcher.
  2. The user installs and runs the application.
  3. Launcher runs the application and passes user parameters via the command line. The authorization token is passed in the xsolla-login-token parameter.
  4. The application processes command line parameters and obtains a token.
  5. The application validates the received token.
  6. The application automatically authorizes the user without displaying an authorization page.

To implement the described logic, use the AuthViaXsollaLauncher SDK method.

Example of a script for authentication via Launcher:

Copy
Full screen
Small screen
using UnityEngine;
using Xsolla.Auth;
using Xsolla.Core;

namespace Xsolla.Samples.Authorization
{
	public class AuthorizationViaXsollaLauncher : MonoBehaviour
	{
		private void Start()
		{
			// Start authorization via Xsolla Launcher
			// Pass callback functions for success and error cases
			XsollaAuth.AuthViaXsollaLauncher(OnSuccess, OnError);
		}

		private void OnSuccess()
		{
			Debug.Log("Authorization successful");
			// Add actions taken in case of success
		}

		private void OnError(Error error)
		{
			Debug.LogError($"Authorization failed. Error: {error.errorMessage}");
			// Add actions taken in case of error
		}
	}
}

Create an application build

  1. Go to your Unity project.
  2. Make sure that the SDK settings indicate the Login project ID specified in your Publisher Account in the Launcher settings (Launcher > General settings > Authentication).

  1. Run the user authorization scene, where the token is processed.
  2. Click File > Build settings in the main menu and then click Add Open Scenes. Make sure the authorization scene is added first in the list.
  3. Click Build.
  4. In the pop-up window, specify the path to the directory where the finished build will be placed.
Was this article helpful?
Thank you!
Is there anything we can improve? Message
We’re sorry to hear that
Please explain why this article wasn’t helpful to you. Message
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.
Hide

How to set up native authentication via Steam

Native authentication allows players to enter your application via the installed Steam application.

To set up native authentication:

  1. Set up silent authentication via Steam in Publisher Account.
  2. Configure your Unity project.
  3. Implement logic for authentication via Steam.
  4. Ensure authentication via Steam.

Configure your Unity project

Note
The SDK uses the Steamworks.NET library to interact with Steam, which comes with the SDK and is located in the Assets/Xsolla/ThirdParty/Steamworks.NET directory.
  1. Open the steam_appid.txt file, which is located in the root folder of the Unity project.
  2. Specify your application ID in Steam in the file and save the changes. The default value in the file is 480, which is the ID of the Steam test project.
  3. Restart the Unity editor for the changes to take effect.

Implement logic for authentication via Steam

To start authentication, use the SilentAuth SDK method and pass the following parameters to it:

  • providerName — the application’s publishing platform. Pass steam as a value.
  • appId — your application ID in Steam. The value must match the value specified in the steam_appid.txt file.
  • sessionTicket — Steam session ticket. To get it, call the SteamUtils.GetSteamSessionTicket() method.
  • onSuccess — successful user authentication callback.
  • onError — error callback.

Example of a script for authentication via Steam:

Copy
Full screen
Small screen
using UnityEngine;
using Xsolla.Auth;
using Xsolla.Core;

namespace Xsolla.Samples.Steam
{
	public class SteamNativeAuthorization : MonoBehaviour
	{
		private void Start()
		{
			// Get the steam session ticket from `SteamUtils` class
			var steamSessionTicket = SteamUtils.GetSteamSessionTicket();

			// Start silent authentication
			// Pass `steam` as `providerName` parameter
			// Pass your `Steam App ID` as `appId` parameter. We use `480` as an example
			// Pass `steamSessionTicket` variable as the `sessionTicket` parameter
			// Pass callback functions for success and error cases
			XsollaAuth.SilentAuth("steam", "480", steamSessionTicket, OnSuccess, OnError);
		}

		private void OnSuccess()
		{
			Debug.Log("Authorization successful");
			// Add actions taken in case of success
		}

		private void OnError(Error error)
		{
			Debug.LogError($"Authorization failed. Error: {error.errorMessage}");
			// Add actions taken in case of error
		}
	}
}

Ensure authentication via Steam

  1. Launch Steam and log in. Otherwise, the callback function is called with the Requested steam session ticket is null. Please check your Steam settings error.
  2. Create the build of your Unity project for a stand-alone platform and run it or start a scene in the Unity editor. If everything is correct, you are automatically logged into the applictaion.
Was this article helpful?
Thank you!
Is there anything we can improve? Message
We’re sorry to hear that
Please explain why this article wasn’t helpful to you. Message
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.
Hide
Last updated: October 10, 2023

Found a typo or other text error? Select the text and press Ctrl+Enter.

Report a problem
We always review our content. Your feedback helps us improve it.
Provide an email so we can follow up
Thank you for your feedback!