Install and initialize the module
To use the 'Account and authentication' features, you must install the authentication module in the Hive Axyl SDK and register it at SDK global initialization. Before installing the module, first complete Install the Hive Axyl SDK.
1. Install modules
Install modules by adding their packages to the project dependencies in Unity Package Manager. The global common package com.com2usplatform.hiveaxyl.core must be installed first.
1.1. Authentication module
To use the 'Account and authentication' features, install the following package.
com.com2usplatform.hiveaxyl.auth: Package that containsIAuthService, which provides login method retrieval, account linking and unlinking, and usage restriction retrieval, andITokenService, which provides token issuance
1.2. Secure storage module
com.com2usplatform.hiveaxyl.storage provides ISecureStorage, which encrypts values that must remain for the next launch, such as access tokens or refresh tokens, and keeps them in the device's secure storage. You need it to implement Automatic login and Switch between accounts, or to delete saved tokens in Log out and Delete an account. If you use only the other 'Account and authentication' features, you do not need to install it.
Note
Secure storage works only in iOS, macOS, Android, and Windows player builds. It is not registered in the Unity Editor, so check it with HiveCore.TryResolve<ISecureStorage>(out var storage) instead of HiveCore.Resolve<ISecureStorage>() before you use it. On Windows, Microsoft Visual C++ 2015-2022 Redistributable (x64) must be installed on every device that runs the app.
1.3. Verify the installation
If the following using statements do not cause compile errors, the installation is complete.
For package selection and the installation procedure, see Get started - Install modules.
2. Initialize the module
Register the module together at SDK global initialization. In the registration step of HiveBootstrap.Initialize, calling AddAuth() registers IAuthService, calling AddToken() registers ITokenService, and calling AddSecureStorage() registers ISecureStorage.
using Hive.Axyl.Core;
using Hive.Axyl.Auth;
using Hive.Axyl.Storage;
var config = CoreConfig.CreateBuilder("{appId}").Build();
HiveBootstrap.Initialize(config, builder =>
{
builder.AddAuth()
.AddToken()
.AddSecureStorage(); // Register this when you save tokens on the device or delete saved tokens.
});
2.1. Check the initialization result
After initialization, retrieve the services you need with HiveCore.Resolve<T>() and use them.
IAuthService auth = HiveCore.Resolve<IAuthService>();
ITokenService token = HiveCore.Resolve<ITokenService>();
// Secure storage is registered only in player builds for supported OSs.
if (HiveCore.TryResolve<ISecureStorage>(out ISecureStorage storage))
{
// Use storage in the token save and restore logic.
}
If IAuthService and ITokenService are returned normally, initialization is complete. For the global initialization procedure, see Get started - Initialize the SDK.
Next steps
To decide which login methods to show on the login screen, see Get supported login methods.