Install and initialize the module
Login with an external authentication provider requires the common authentication module and the Add-ons that match the login methods your app provides. Implement each login method after you finish installation and initialization.
Before you begin, complete Step 2. Install the Hive Axyl SDK.
1. Install modules
Install modules by adding packages to your project dependencies in Unity Package Manager. The global common package com.com2usplatform.hiveaxyl.core must be installed first.
1.1. Install common modules
Every login method uses the following packages.
com.com2usplatform.hiveaxyl.auth: Authentication APIs such as external authentication provider login, external authorization code exchange, and token issuancecom.com2usplatform.hiveaxyl.storage: Saves values to and loads them from the device's secure storage. Used to storedeviceKeyand refresh tokens
1.2. Install Add-ons for each login method
Also install the Add-ons that match the combinations of external authentication providers and OSs your app will support. To see which Add-ons each combination needs, see Login approach by OS. Custom account login does not go through an external authentication provider, so you do not install an Add-on for it.
| Add-on | Package | Supported OSs |
|---|---|---|
| Web login session | com.com2usplatform.hiveaxyl.auth.addon.webauth | Android, iOS, macOS, Windows |
| Google login | com.com2usplatform.hiveaxyl.auth.addon.credentialmanager | Android |
| Apple login | com.com2usplatform.hiveaxyl.auth.addon.apple | iOS, macOS |
| Google Play Games login | com.com2usplatform.hiveaxyl.auth.addon.gpg | Android |
| Steam login | com.com2usplatform.hiveaxyl.auth.addon.steam | Windows, macOS |
For example, to provide Sign in with Google on both Android and other OSs, install com.com2usplatform.hiveaxyl.auth.addon.credentialmanager and com.com2usplatform.hiveaxyl.auth.addon.webauth together.
When you install an Add-on, the external libraries that the Add-on uses are installed with it. The Steam login Add-on brings in the com.com2usplatform.hiveaxyl.steamworks package, which wraps the Steamworks SDK; the Google login Add-on brings in the androidx.credentials family of libraries; and the Google Play Games login Add-on brings in com.google.android.gms:play-services-games-v2. You do not need to add these libraries to your project yourself.
Do not install Add-ons that you do not use. The external libraries of installed Add-ons are included in the build output and increase the app size.
1.3. Verify the installation
If the following using directives compile without errors, the installation is complete. Check only the Add-ons you installed.
For package selection and the installation procedure, see Step 3. Install modules.
2. Initialize modules
Register the modules used for login during global SDK initialization. Call the following methods in the registration step of HiveBootstrap.Initialize.
| Registration method | Registered type | Role | Registered OS |
|---|---|---|---|
AddAuth() | IAuthService | Login and external authorization code exchange | All OSs |
AddToken() | ITokenService | Exchanges an authorization code for an access token and a refresh token | All OSs |
AddSecureStorage() | ISecureStorage | Stores deviceKey and tokens | Android, iOS, macOS, Windows |
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();
});
IAuthService auth = HiveCore.Resolve<IAuthService>();
ITokenService token = HiveCore.Resolve<ITokenService>();
For the global initialization procedure, see Step 4. Initialize the SDK.
ISessionManager, which you use to register the session after login, has no separate registration method. HiveBootstrap.Initialize registers it automatically, so retrieve it directly with HiveCore.Resolve<ISessionManager>().
2.1. Initialize Add-ons for each login method
Register the Add-ons you installed in the same registration step.
| Registration method | Registered type | Registered OS |
|---|---|---|
AddWebAuth() | IExternalUserAgent | Android, iOS, macOS, Windows |
AddCredentialManager() | IAndroidCredentialManagerPlugin | Android |
AddAppleSignIn() | IAppleSignInPlugin | iOS, macOS |
AddGooglePlayGames() | IGooglePlayGamesPlugin | Android |
AddSteamAuth() | ISteamPlugin | Windows, macOS |
Registration methods do not cause errors on any OS. On unsupported OSs and in the Unity Editor, only the registration is skipped. So you can register all the Add-ons your app supports at once, as shown below.
using Hive.Axyl.Core;
using Hive.Axyl.Auth;
using Hive.Axyl.Storage;
using Hive.Axyl.Auth.Addon.WebAuth;
using Hive.Axyl.Auth.Addon.CredentialManager;
using Hive.Axyl.Auth.Addon.Apple;
using Hive.Axyl.Auth.Addon.GPG;
using Hive.Axyl.Auth.Addon.Steam;
HiveBootstrap.Initialize(config, builder =>
{
builder.AddAuth()
.AddToken()
.AddSecureStorage()
.AddWebAuth()
.AddCredentialManager()
.AddAppleSignIn()
.AddGooglePlayGames()
.AddSteamAuth();
});
2.2. Check the initialization result
If HiveCore.Resolve<IAuthService>() and HiveCore.Resolve<ITokenService>() return instances normally, the common modules are initialized.
Secure storage and Add-ons are registered only on supported OSs, so retrieving them with HiveCore.Resolve<T>() throws RegistrationNotFoundException on unsupported OSs and in the Unity Editor. When you retrieve ISecureStorage and Add-ons, first check whether they are registered with HiveCore.TryResolve<T>(), and if they are not registered, branch to another approach for that OS.
using Hive.Axyl.Core;
using Hive.Axyl.Auth.Addon.CredentialManager;
using Hive.Axyl.Auth.Addon.WebAuth;
// On Android, use the Google login Add-on; on other OSs, use the web login session.
if (HiveCore.TryResolve<IAndroidCredentialManagerPlugin>(out var googlePlugin))
{
// Get credentials with the Google login Add-on.
}
else if (HiveCore.TryResolve<IExternalUserAgent>(out var webAuth))
{
// Get credentials with the web login session.
}
Next steps
First check the methods that all login methods use in common, and then set up the integration for the login methods your app provides.
- Web login session
- Exchange external authorization codes
- Log in with an external authentication provider
- Sign in with Google: Step 1. Set up the integration
- Sign in with Apple: Step 1. Set up the integration
- Google Play Games login for mobile apps: Step 1. Set up the integration
- Log in with a Steam account: Step 1. Set up the integration
- Log in with an X (Twitter) account: Step 1. Set up the integration
- Log in with a custom account