NAV
Unity (UniTask) Unity Unity (Legacy) Unreal Engine 5 Unreal Engine 4

GS2-Auth

GS2-SDK for Game Engine Reference

SDK for Game Engine

Models

EzAccessToken

Type Description
token string Access token
userId string User Id
expire long Effective date

Methods

login

login

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Auth.AccessToken(
    );
    var result = await domain.LoginAsync(
        keyId: "key-0001",
        body: "body",
        signature: "signature"
    );
    var token = result.Token;
    var userId = result.UserId;
    var expire = result.Expire;
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Auth.AccessToken(
    );
    var future = domain.Login(
        keyId: "key-0001",
        body: "body",
        signature: "signature"
    );
    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;
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzLoginResult> asyncResult = null;
    var current = gs2.Auth.Login(
        callback: r => { asyncResult = r; },
        keyId: "key-0001",
        body: "body",
        signature: "signature"
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var token = result.Token;
    var userId = result.UserId;
    var expire = result.Expire;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Auth->AccessToken(
    );
    const auto Future = Domain->Login(
        "key-0001",
        "body",
        "signature"
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;
    const auto Token = Result->Token;
    const auto UserId = Result->UserId;
    const auto Expire = Result->Expire;
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->auth.loginBySignature(
    [](gs2::ez::account::AsyncEzLoginBySignatureResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "auth.loginBySignature failed.");
        }
        else
        {
            Token = r.getResult()->getToken();
            UserId = r.getResult()->getUserId();
            Expire = r.getResult()->getExpire();
        }
    },
    TCHAR_TO_ANSI("key-0001"), // keyId
    TCHAR_TO_ANSI("body"), // body
    TCHAR_TO_ANSI("signature") // signature
);

Log in to GS2 with the specified user ID

Specify the result of GS2-Account::Authentication for body and signature.
If body and signature are successfully verified, an access token is responded.
The access token is temporary authentication information with an expiration time of one hour, and is used to identify the game player for each service in GS2.
GS2-Account::Authentication and GS2-Profile::Login are available for Unity and Cocos2d-x.
GS2-Profile::Login is explained in Getting Started => Sample Programs.



Request

Type Require Default Limitation Description
keyId string ~ 1024 chars encryption key GRN
body string ~ 1048576 chars Account credentials to be signed
signature string ~ 1024 chars signature

Result

Type Description
token string access token
userId string User Id
expire long effective date