GS2-Auth SDK for Game Engine API Reference
Model
EzAccessToken
Access token
A model that manages access tokens issued after user authentication. Access tokens are used to identify a session while a user is logged in to the service. Tokens have an expiration time, and when they expire, re-authentication is required.
| Type | Condition | Required | Default | Value Limits | Description | |
|---|---|---|---|---|---|---|
| token | string | ✓ | ~ 1024 chars | Access token A token used to authenticate access. This token is automatically generated by the system and identifies the user’s session. | ||
| userId | string | ✓ | ~ 128 chars | User ID | ||
| expire | long | The absolute time 1 hour after the current time | Expiration time A timestamp indicating the expiration time of the token. When this date is reached, the token becomes invalid. Unix time, milliseconds |
Methods
login
Log in to GS2 using account credentials
Pass the body and signature obtained from GS2-Account::Authentication to log in and receive an access token.
The access token is a temporary login credential valid for 1 hour, and is required to use GS2 services as a specific player.
In most cases, you do not need to call this API directly. The Unity and Unreal Engine 5 SDKs provide Profile::Login, which combines GS2-Account::Authentication and this API into a single call. See Initialization / Game Engine for details.
Request
| Type | Condition | Required | Default | Value Limits | Description | |
|---|---|---|---|---|---|---|
| keyId | string | “grn:gs2:{region}:{ownerId}:key:default:key:default” | ~ 1024 chars | Encryption Key GRN | ||
| body | string | ✓ | ~ 524288 chars | Signed authentication payload | ||
| signature | string | ✓ | ~ 1024 chars | Signature |
Result
| Type | Description | |
|---|---|---|
| token | string | Access token A token used to authenticate access. This token is automatically generated by the system and identifies the user’s session. |
| userId | string | User ID |
| expire | long | Expiration time A timestamp indicating the expiration time of the token. When this date is reached, the token becomes invalid. Unix time, milliseconds |
Implementation Example
var domain = gs2.Auth.AccessToken(
);
var result = await domain.LoginAsync(
body: "body",
signature: "signature",
keyId: "key-0001"
);
var token = result.Token;
var userId = result.UserId;
var expire = result.Expire; var domain = gs2.Auth.AccessToken(
);
var future = domain.LoginFuture(
body: "body",
signature: "signature",
keyId: "key-0001"
);
yield return future;
if (future.Error != null)
{
onError.Invoke(future.Error, null);
yield break;
}
var token = future.Result.Token;
var userId = future.Result.UserId;
var expire = future.Result.Expire; const auto Domain = Gs2->Auth->AccessToken(
);
const auto Future = Domain->Login(
"body", // body
"signature", // signature
"key-0001" // keyId
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
const auto Result = Future->GetTask().Result();
const auto Token = Result->Token;
const auto UserId = Result->UserId;
const auto Expire = Result->Expire;