Auth module
This module handles app user authentication. It provides guest login, username login, external authentication provider (Provider) login, account linking and unlinking, usage restriction retrieval, and the exchange of the authorization code received as a login result for tokens.
Module information
- Package:
com.com2usplatform.hiveaxyl.auth - Namespace:
Hive.Axyl.Auth - Supported platforms: All (server API)
- Minimum requirements: Unity 6000.0+
Provided interfaces
| Interface | Registration method | Description |
|---|---|---|
| IAuthService | AddAuth() | Account creation, login, account linking and unlinking, usage restriction retrieval, logout, account deletion |
| ITokenService | AddToken() | Exchange of an authorization code or a refresh token for an access token |
Login uses the two interfaces in sequence. When a login method of IAuthService returns an authorization code (AuthorizationCode), pass that value to ITokenService.IssueTokenAsync() to get an access token and a refresh token. The authorization code and the tokens are separated to reduce the risk of token exposure.
Registration and retrieval
Register the interfaces you need in the registration step of HiveBootstrap.Initialize, and then retrieve them with HiveCore.Resolve<T>().
using Hive.Axyl.Auth;
using Hive.Axyl.Core;
using Hive.Axyl.Core.Unity; // HiveBootstrap
var config = CoreConfig.CreateBuilder("{appId}").Build();
HiveBootstrap.Initialize(config, builder =>
{
builder.AddAuth()
.AddToken();
});
IAuthService auth = HiveCore.Resolve<IAuthService>();
ITokenService token = HiveCore.Resolve<ITokenService>();
For the installation procedure and initialization options, see Install and initialize the module.
AuthTokenRefresh
static class — namespace Hive.Axyl.Auth
An entry class that turns on automatic access token refresh. When a method is called with an expired access token, it gets a new token with the session's refresh token, refreshes the session, and continues processing the original request.
The refresh handler is built on top of a retry-safe transport layer and registered in Core.
Enable
Connects the automatic refresh handler to Core. Call it only once after HiveBootstrap.Initialize.
| Parameter | Type | Required | Description |
|---|---|---|---|
baseUrl | string | Required | The host root of the token endpoint. It is the same value that ITokenService uses. If you registered AddToken() without arguments, it is https://core-api.hiveaxyl.com. |
clientId | string | Required | The OAuth client identifier sent with the refresh request. |
Exceptions
ArgumentNullException: WhenbaseUrlorclientIdisnullInvalidOperationException: When Core has not been initialized, or when the refresh handler has already been registered
Call example
For when to use it and the session registration procedure, see Automatic login.