API Reference of GS2-Auth SDK

Model

AccessToken

TypeConditionRequireDefaultLimitationDescription
tokenstring~ 1024 charsAccess token
userIdstring~ 128 charsUser Id
expirelongDifference from current time(1 hours)Effective date
timeOffsetint0~ 31536000Correction value for time processing (seconds)

Methods

login

Logs into GS2 with the specified user ID and obtains an access token This API is intended to be called from a trusted game server. It is inappropriate to call it from the client, as there is no validation process for the user ID value.

Request

TypeConditionRequireDefaultLimitationDescription
userIdstring~ 128 charsUser Id
timeOffsetint0~ 31536000Correction value for time processing (seconds)

Result

TypeDescription
tokenstringaccess token
userIdstringUser Id
expirelongeffective date

Implementation Example

import "github.com/gs2io/gs2-golang-sdk/core"
import "github.com/gs2io/gs2-golang-sdk/auth"
import "github.com/openlyinc/pointy"

session := core.Gs2RestSession{
    Credential: &core.BasicGs2Credential{
        ClientId: "your client id",
        ClientSecret: "your client secret",
    },
    Region: core.ApNortheast1,
}

if err := session.Connect(); err != nil {
    panic("error occurred")
}

client := auth.Gs2AuthRestClient{
    Session: &session,
}
result, err := client.Login(
    &auth.LoginRequest {
        UserId: pointy.String("user-0001"),
        TimeOffset: nil,
    }
)
if err != nil {
    panic("error occurred")
}
token := result.Token
userId := result.UserId
expire := result.Expire
use Gs2\Core\Model\BasicGs2Credential;
use Gs2\Core\Model\Region;
use Gs2\Core\Net\Gs2RestSession;
use Gs2\Core\Exception\Gs2Exception;
use Gs2\Auth\Gs2AuthRestClient;
use Gs2\Auth\Request\LoginRequest;

$session = new Gs2RestSession(
    new BasicGs2Credential(
        "your client id",
        "your client secret"
    ),
    Region::AP_NORTHEAST_1
);

$session->open();

$client = new Gs2AccountRestClient(
    $session
);

try {
    $result = $client->login(
        (new LoginRequest())
            ->withUserId("user-0001")
            ->withTimeOffset(null)
    );
    $token = $result->getToken();
    $userId = $result->getUserId();
    $expire = $result->getExpire();
} catch (Gs2Exception $e) {
    exit("error occurred")
}
import io.gs2.core.model.Region;
import io.gs2.core.model.BasicGs2Credential;
import io.gs2.core.rest.Gs2RestSession;
import io.gs2.core.exception.Gs2Exception;
import io.gs2.auth.rest.Gs2AuthRestClient;
import io.gs2.auth.request.LoginRequest;
import io.gs2.auth.result.LoginResult;

Gs2RestSession session = new Gs2RestSession(
    Region.AP_NORTHEAST_1,
    new BasicGs2Credential(
        'your client id',
        'your client secret'
    )
);
session.connect();
Gs2AuthRestClient client = new Gs2AuthRestClient(session);

try {
    LoginResult result = client.login(
        new LoginRequest()
            .withUserId("user-0001")
            .withTimeOffset(null)
    );
    String token = result.getToken();
    String userId = result.getUserId();
    long expire = result.getExpire();
} catch (Gs2Exception e) {
    System.exit(1);
}
using Gs2.Core.Model.Region;
using Gs2.Core.Model.BasicGs2Credential;
using Gs2.Core.Net.Gs2RestSession;
using Gs2.Core.Exception.Gs2Exception;
using Gs2.Core.AsyncResult;
using Gs2.Gs2Auth.Gs2AuthRestClient;
using Gs2.Gs2Auth.Request.LoginRequest;
using Gs2.Gs2Auth.Result.LoginResult;

var session = new Gs2RestSession(
    new BasicGs2Credential(
        'your client id',
        'your client secret'
    ),
    Region.ApNortheast1
);
yield return session.Open();
var client = new Gs2AuthRestClient(session);

AsyncResult<Gs2.Gs2Auth.Result.LoginResult> asyncResult = null;
yield return client.Login(
    new Gs2.Gs2Auth.Request.LoginRequest()
        .WithUserId("user-0001")
        .WithTimeOffset(null),
    r => asyncResult = r
);
if (asyncResult.Error != null) {
    throw asyncResult.Error;
}
var result = asyncResult.Result;
var token = result.Token;
var userId = result.UserId;
var expire = result.Expire;
import Gs2Core from '@/gs2/core';
import * as Gs2Auth from '@/gs2/auth';

const session = new Gs2Core.Gs2RestSession(
    "ap-northeast-1",
    new Gs2Core.BasicGs2Credential(
        'your client id',
        'your client secret'
    )
);
await session.connect();
const client = new Gs2Auth.Gs2AuthRestClient(session);

try {
    const result = await client.login(
        new Gs2Auth.LoginRequest()
            .withUserId("user-0001")
            .withTimeOffset(null)
    );
    const token = result.getToken();
    const userId = result.getUserId();
    const expire = result.getExpire();
} catch (e) {
    process.exit(1);
}
from gs2 import core
from gs2 import auth

session = core.Gs2RestSession(
    core.BasicGs2Credential(
        'your client id',
        'your client secret'
    ),
    "ap-northeast-1",
)
session.connect()
client = auth.Gs2AuthRestClient(session)

try:
    result = client.login(
        auth.LoginRequest()
            .with_user_id('user-0001')
            .with_time_offset(None)
    )
    token = result.token
    user_id = result.user_id
    expire = result.expire
except core.Gs2Exception as e:
    exit(1)
client = gs2('auth')

api_result = client.login({
    userId='user-0001',
    timeOffset=nil,
})

if(api_result.isError) then
    -- When error occurs
    fail(api_result['statusCode'], api_result['message'])
end

result = api_result.result
token = result.token;
userId = result.userId;
expire = result.expire;

loginBySignature

Log in to GS2 with the specified user ID and obtain an access token By performing signature verification of the user ID, this API is safe to invoke from the client.

Request

TypeConditionRequireDefaultLimitationDescription
keyIdstring~ 1024 charsencryption key GRN
bodystring~ 1048576 charsAccount credentials to be signed
signaturestring~ 1024 charssignature

Result

TypeDescription
tokenstringaccess token
userIdstringUser Id
expirelongeffective date

Implementation Example

import "github.com/gs2io/gs2-golang-sdk/core"
import "github.com/gs2io/gs2-golang-sdk/auth"
import "github.com/openlyinc/pointy"

session := core.Gs2RestSession{
    Credential: &core.BasicGs2Credential{
        ClientId: "your client id",
        ClientSecret: "your client secret",
    },
    Region: core.ApNortheast1,
}

if err := session.Connect(); err != nil {
    panic("error occurred")
}

client := auth.Gs2AuthRestClient{
    Session: &session,
}
result, err := client.LoginBySignature(
    &auth.LoginBySignatureRequest {
        KeyId: pointy.String("key-0001"),
        Body: pointy.String("body"),
        Signature: pointy.String("signature"),
    }
)
if err != nil {
    panic("error occurred")
}
token := result.Token
userId := result.UserId
expire := result.Expire
use Gs2\Core\Model\BasicGs2Credential;
use Gs2\Core\Model\Region;
use Gs2\Core\Net\Gs2RestSession;
use Gs2\Core\Exception\Gs2Exception;
use Gs2\Auth\Gs2AuthRestClient;
use Gs2\Auth\Request\LoginBySignatureRequest;

$session = new Gs2RestSession(
    new BasicGs2Credential(
        "your client id",
        "your client secret"
    ),
    Region::AP_NORTHEAST_1
);

$session->open();

$client = new Gs2AccountRestClient(
    $session
);

try {
    $result = $client->loginBySignature(
        (new LoginBySignatureRequest())
            ->withKeyId("key-0001")
            ->withBody("body")
            ->withSignature("signature")
    );
    $token = $result->getToken();
    $userId = $result->getUserId();
    $expire = $result->getExpire();
} catch (Gs2Exception $e) {
    exit("error occurred")
}
import io.gs2.core.model.Region;
import io.gs2.core.model.BasicGs2Credential;
import io.gs2.core.rest.Gs2RestSession;
import io.gs2.core.exception.Gs2Exception;
import io.gs2.auth.rest.Gs2AuthRestClient;
import io.gs2.auth.request.LoginBySignatureRequest;
import io.gs2.auth.result.LoginBySignatureResult;

Gs2RestSession session = new Gs2RestSession(
    Region.AP_NORTHEAST_1,
    new BasicGs2Credential(
        'your client id',
        'your client secret'
    )
);
session.connect();
Gs2AuthRestClient client = new Gs2AuthRestClient(session);

try {
    LoginBySignatureResult result = client.loginBySignature(
        new LoginBySignatureRequest()
            .withKeyId("key-0001")
            .withBody("body")
            .withSignature("signature")
    );
    String token = result.getToken();
    String userId = result.getUserId();
    long expire = result.getExpire();
} catch (Gs2Exception e) {
    System.exit(1);
}
using Gs2.Core.Model.Region;
using Gs2.Core.Model.BasicGs2Credential;
using Gs2.Core.Net.Gs2RestSession;
using Gs2.Core.Exception.Gs2Exception;
using Gs2.Core.AsyncResult;
using Gs2.Gs2Auth.Gs2AuthRestClient;
using Gs2.Gs2Auth.Request.LoginBySignatureRequest;
using Gs2.Gs2Auth.Result.LoginBySignatureResult;

var session = new Gs2RestSession(
    new BasicGs2Credential(
        'your client id',
        'your client secret'
    ),
    Region.ApNortheast1
);
yield return session.Open();
var client = new Gs2AuthRestClient(session);

AsyncResult<Gs2.Gs2Auth.Result.LoginBySignatureResult> asyncResult = null;
yield return client.LoginBySignature(
    new Gs2.Gs2Auth.Request.LoginBySignatureRequest()
        .WithKeyId("key-0001")
        .WithBody("body")
        .WithSignature("signature"),
    r => asyncResult = r
);
if (asyncResult.Error != null) {
    throw asyncResult.Error;
}
var result = asyncResult.Result;
var token = result.Token;
var userId = result.UserId;
var expire = result.Expire;
import Gs2Core from '@/gs2/core';
import * as Gs2Auth from '@/gs2/auth';

const session = new Gs2Core.Gs2RestSession(
    "ap-northeast-1",
    new Gs2Core.BasicGs2Credential(
        'your client id',
        'your client secret'
    )
);
await session.connect();
const client = new Gs2Auth.Gs2AuthRestClient(session);

try {
    const result = await client.loginBySignature(
        new Gs2Auth.LoginBySignatureRequest()
            .withKeyId("key-0001")
            .withBody("body")
            .withSignature("signature")
    );
    const token = result.getToken();
    const userId = result.getUserId();
    const expire = result.getExpire();
} catch (e) {
    process.exit(1);
}
from gs2 import core
from gs2 import auth

session = core.Gs2RestSession(
    core.BasicGs2Credential(
        'your client id',
        'your client secret'
    ),
    "ap-northeast-1",
)
session.connect()
client = auth.Gs2AuthRestClient(session)

try:
    result = client.login_by_signature(
        auth.LoginBySignatureRequest()
            .with_key_id('key-0001')
            .with_body('body')
            .with_signature('signature')
    )
    token = result.token
    user_id = result.user_id
    expire = result.expire
except core.Gs2Exception as e:
    exit(1)
client = gs2('auth')

api_result = client.login_by_signature({
    keyId='key-0001',
    body='body',
    signature='signature',
})

if(api_result.isError) then
    -- When error occurs
    fail(api_result['statusCode'], api_result['message'])
end

result = api_result.result
token = result.token;
userId = result.userId;
expire = result.expire;