Service Account Usage
A service account allows authorization for internal headless scenarios (automated scripts, tests, and so on).
Generate a Service Account
- As the owner or manager of a Unity Organization, you can create a Service Account, and assign it any roles for this organization and its projects depending on your needs.
- When the account is created, store its credentials (
key IDandsecret key) in a secure and private location. - You can now refer to those credentials in your application, following the 'keyID:secret' format, to authorize your calls to Unity Cloud services.
Using the ServiceAccountAuthenticator
The ServiceAccountAuthenticator class implements the IAuthenticator interface. When the class is instantiated, it can be either injected in a CompositeAuthenticatorSettings to be activated from environment variables or command-line argument, or it can be directly injected in a ServiceHttpClient to access Unity Cloud services.
var platformSupport = PlatformSupportFactory.GetAuthenticationPlatformSupport();
var httpClient = new UnityHttpClient();
var playerSettings = UnityCloudPlayerSettings.Instance;
var serviceHostResolver = ServiceHostResolverFactory.Create();
var serviceAccountAuthenticatorSettingsBuilder =
new ServiceAccountAuthenticatorSettingsBuilder(httpClient, serviceHostResolver, platformSupport)
.SetAppIdProvider(playerSettings);
m_ServiceAccountAuthenticator = new ServiceAccountAuthenticator(serviceAccountAuthenticatorSettingsBuilder.Build());
m_ServiceHttpClient = new ServiceHttpClient(httpClient, m_ServiceAccountAuthenticator, playerSettings);
Inject the Service Account credentials in your Unity Cloud application
You can inject the Service Account credentials by either using command-line arguments when launching the application or by defining an environment variable at the OS level as follows:
Inject credentials from a command-line argument passed to the Unity Cloud application.
./MyApp.exe -UNITY_SERVICE_ACCOUNT_CREDENTIALS [keyID:secret]Inject credentials from a
UNITY_SERVICE_ACCOUNT_CREDENTIALSenvironment variable set before running the Unity Cloud application.