> For the complete documentation index, see [llms.txt](/llms.txt)

# GS2-Auth SDK API Reference

Specification of models and API references for GS2-Auth SDK for various programming languages



## Models

### AccessToken

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<br>A token used to authenticate access.<br>This token is automatically generated by the system and identifies the user's session. |
| userId | string |  | ✓ |  |  ~ 128 chars | User ID |
| federationFromUserId | string |  |  |  |  ~ 128 chars | Federation original user ID<br>The user ID of the original user who initiated the ID federation. When acting as another user through ID federation, this field stores the original acting user's ID. |
| expire | long |  |  | Absolute time 1 hour after the current time |  | Expiration time<br>A timestamp indicating the expiration time of the token. When this date is reached, the token becomes invalid.<br>Unix time, milliseconds |
| timeOffset | int |  |  | 0 | 0 ~ 315360000 | Time offset from the current time (number of seconds relative to the current time)<br>The time offset represents the difference from the current server time in seconds.<br>This value is used when in-game events or features need to operate according to a specific time. |



---
## Methods

### login

Log in to GS2 by User ID

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.
You can optionally specify a time offset (in seconds) to pseudo-advance the current time for the logged-in user, which is useful for testing future event schedules.
The returned access token has an expiration time, after which it becomes invalid.



#### Request

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| userId | string |  | ✓|  |  ~ 128 chars | User ID |
| timeOffset | int |  | | 0 | 0 ~ 315360000 | Time offset from the current time (number of seconds relative to the current time)<br>The time offset represents the difference from the current server time in seconds.<br>This value is used when in-game events or features need to operate according to a specific time. |
| timeOffsetToken | string |  | |  |  ~ 1024 chars | Time offset token |

#### Result

|  | Type | Description |
| --- | --- | --- |
| token | string | Access token<br>A token used to authenticate access.<br>This token is automatically generated by the system and identifies the user's session. |
| userId | string | User ID |
| expire | long | Expiration time<br>A timestamp indicating the expiration time of the token. When this date is reached, the token becomes invalid.<br>Unix time, milliseconds |

#### Implementation Example




**Go**
```go

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,
        TimeOffsetToken: nil,
    }
)
if err != nil {
    panic("error occurred")
}
token := result.Token
userId := result.UserId
expire := result.Expire

```

**PHP**
```php

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 Gs2AuthRestClient(
    $session
);

try {
    $result = $client->login(
        (new LoginRequest())
            ->withUserId("user-0001")
            ->withTimeOffset(null)
            ->withTimeOffsetToken(null)
    );
    $token = $result->getToken();
    $userId = $result->getUserId();
    $expire = $result->getExpire();
} catch (Gs2Exception $e) {
    exit("error occurred")
}

```

**Java**
```java

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)
            .withTimeOffsetToken(null)
    );
    String token = result.getToken();
    String userId = result.getUserId();
    long expire = result.getExpire();
} catch (Gs2Exception e) {
    System.exit(1);
}

```

**C#**
```csharp

using Gs2.Core;
using Gs2.Core.Model;
using Gs2.Core.Net;
using Gs2.Core.Exception;

var session = new Gs2RestSession(
    new BasicGs2Credential(
        "your client id",
        "your client secret"
    ),
    Region.ApNortheast1
);
yield return session.OpenAsync(r => { });
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)
        .WithTimeOffsetToken(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;

```

**TypeScript**
```typescript

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)
            .withTimeOffsetToken(null)
    );
    const token = result.getToken();
    const userId = result.getUserId();
    const expire = result.getExpire();
} catch (e) {
    process.exit(1);
}

```

**Python**
```python

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)
            .with_time_offset_token(None)
    )
    token = result.token
    user_id = result.user_id
    expire = result.expire
except core.Gs2Exception as e:
    exit(1)


```

**GS2-Script**
```lua

client = gs2('auth')

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

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

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

```

**GS2-Script(Async)**
```lua

client = gs2('auth')

api_result_handler = client.login_async({
    userId="user-0001",
    timeOffset=nil,
    timeOffsetToken=nil,
})

api_result = api_result_handler()  -- Call the handler to get the result

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

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

```




---

### loginBySignature

Login with Account Authentication

Log in to GS2 by verifying signed account authentication information and obtain an access token.
By performing signature verification of the signed authentication payload, this API is safe to call from clients.
The body and signature are typically obtained from the GS2-Account Authentication API, and the key ID specifies the GS2-Key encryption key used for signature verification.
The returned access token has an expiration time, after which it becomes invalid.



#### 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<br>A token used to authenticate access.<br>This token is automatically generated by the system and identifies the user's session. |
| userId | string | User ID |
| expire | long | Expiration time<br>A timestamp indicating the expiration time of the token. When this date is reached, the token becomes invalid.<br>Unix time, milliseconds |

#### Implementation Example




**Go**
```go

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

```

**PHP**
```php

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 Gs2AuthRestClient(
    $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")
}

```

**Java**
```java

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);
}

```

**C#**
```csharp

using Gs2.Core;
using Gs2.Core.Model;
using Gs2.Core.Net;
using Gs2.Core.Exception;

var session = new Gs2RestSession(
    new BasicGs2Credential(
        "your client id",
        "your client secret"
    ),
    Region.ApNortheast1
);
yield return session.OpenAsync(r => { });
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;

```

**TypeScript**
```typescript

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);
}

```

**Python**
```python

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)


```

**GS2-Script**
```lua

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['errorMessage'])
end

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

```

**GS2-Script(Async)**
```lua

client = gs2('auth')

api_result_handler = client.login_by_signature_async({
    keyId="key-0001",
    body="body",
    signature="signature",
})

api_result = api_result_handler()  -- Call the handler to get the result

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

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

```




---

### federation

User ID Federation

Obtains an access token that allows you to act as another user based on the specified original user ID.
This is useful for scenarios such as guild-to-member operations, where a guild master needs to perform actions on behalf of another user.
When issuing a transaction using this access token, #{userId} in the transaction action is replaced with the federated user ID,
and #{originalUserId} is replaced with the original user ID.

By specifying a policy document, you can set stricter constraints on the permissions that the credentials have as a federated user when calling the API.
The returned access token has an expiration time, after which it becomes invalid.



#### Request

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| originalUserId | string |  | ✓|  |  ~ 128 chars | Federation original user ID |
| userId | string |  | ✓|  |  ~ 128 chars | Federated user ID |
| policyDocument | string |  | |  |  ~ 524288 chars | Policy document |
| timeOffset | int |  | | 0 | 0 ~ 315360000 | Time offset from the current time (number of seconds relative to the current time)<br>The time offset represents the difference from the current server time in seconds.<br>This value is used when in-game events or features need to operate according to a specific time. |
| timeOffsetToken | string |  | |  |  ~ 1024 chars | Time offset token |

#### Result

|  | Type | Description |
| --- | --- | --- |
| token | string | Access token<br>A token used to authenticate access.<br>This token is automatically generated by the system and identifies the user's session. |
| userId | string | User ID |
| expire | long | Expiration time<br>A timestamp indicating the expiration time of the token. When this date is reached, the token becomes invalid.<br>Unix time, milliseconds |

#### Implementation Example




**Go**
```go

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.Federation(
    &auth.FederationRequest {
        OriginalUserId: pointy.String("user-0001"),
        UserId: pointy.String("user-0002"),
        PolicyDocument: pointy.String("{\n  \"Version\": \"2016-04-01\",\n  \"Statements\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Actions\": [\n        \"Gs2Inbox:SendMessage\"\n      ],\n      \"Resources\": [\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001\",\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*\"\n      ]\n    }\n  ]\n}"),
        TimeOffset: nil,
        TimeOffsetToken: nil,
    }
)
if err != nil {
    panic("error occurred")
}
token := result.Token
userId := result.UserId
expire := result.Expire

```

**PHP**
```php

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\FederationRequest;

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

$session->open();

$client = new Gs2AuthRestClient(
    $session
);

try {
    $result = $client->federation(
        (new FederationRequest())
            ->withOriginalUserId("user-0001")
            ->withUserId("user-0002")
            ->withPolicyDocument("{\n  \"Version\": \"2016-04-01\",\n  \"Statements\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Actions\": [\n        \"Gs2Inbox:SendMessage\"\n      ],\n      \"Resources\": [\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001\",\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*\"\n      ]\n    }\n  ]\n}")
            ->withTimeOffset(null)
            ->withTimeOffsetToken(null)
    );
    $token = $result->getToken();
    $userId = $result->getUserId();
    $expire = $result->getExpire();
} catch (Gs2Exception $e) {
    exit("error occurred")
}

```

**Java**
```java

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.FederationRequest;
import io.gs2.auth.result.FederationResult;

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

try {
    FederationResult result = client.federation(
        new FederationRequest()
            .withOriginalUserId("user-0001")
            .withUserId("user-0002")
            .withPolicyDocument("{\n  \"Version\": \"2016-04-01\",\n  \"Statements\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Actions\": [\n        \"Gs2Inbox:SendMessage\"\n      ],\n      \"Resources\": [\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001\",\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*\"\n      ]\n    }\n  ]\n}")
            .withTimeOffset(null)
            .withTimeOffsetToken(null)
    );
    String token = result.getToken();
    String userId = result.getUserId();
    long expire = result.getExpire();
} catch (Gs2Exception e) {
    System.exit(1);
}

```

**C#**
```csharp

using Gs2.Core;
using Gs2.Core.Model;
using Gs2.Core.Net;
using Gs2.Core.Exception;

var session = new Gs2RestSession(
    new BasicGs2Credential(
        "your client id",
        "your client secret"
    ),
    Region.ApNortheast1
);
yield return session.OpenAsync(r => { });
var client = new Gs2AuthRestClient(session);

AsyncResult<Gs2.Gs2Auth.Result.FederationResult> asyncResult = null;
yield return client.Federation(
    new Gs2.Gs2Auth.Request.FederationRequest()
        .WithOriginalUserId("user-0001")
        .WithUserId("user-0002")
        .WithPolicyDocument("{\n  \"Version\": \"2016-04-01\",\n  \"Statements\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Actions\": [\n        \"Gs2Inbox:SendMessage\"\n      ],\n      \"Resources\": [\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001\",\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*\"\n      ]\n    }\n  ]\n}")
        .WithTimeOffset(null)
        .WithTimeOffsetToken(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;

```

**TypeScript**
```typescript

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.federation(
        new Gs2Auth.FederationRequest()
            .withOriginalUserId("user-0001")
            .withUserId("user-0002")
            .withPolicyDocument("{\n  \"Version\": \"2016-04-01\",\n  \"Statements\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Actions\": [\n        \"Gs2Inbox:SendMessage\"\n      ],\n      \"Resources\": [\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001\",\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*\"\n      ]\n    }\n  ]\n}")
            .withTimeOffset(null)
            .withTimeOffsetToken(null)
    );
    const token = result.getToken();
    const userId = result.getUserId();
    const expire = result.getExpire();
} catch (e) {
    process.exit(1);
}

```

**Python**
```python

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.federation(
        auth.FederationRequest()
            .with_original_user_id('user-0001')
            .with_user_id('user-0002')
            .with_policy_document('{\n  "Version": "2016-04-01",\n  "Statements": [\n    {\n      "Effect": "Allow",\n      "Actions": [\n        "Gs2Inbox:SendMessage"\n      ],\n      "Resources": [\n        "grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001",\n        "grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*"\n      ]\n    }\n  ]\n}')
            .with_time_offset(None)
            .with_time_offset_token(None)
    )
    token = result.token
    user_id = result.user_id
    expire = result.expire
except core.Gs2Exception as e:
    exit(1)


```

**GS2-Script**
```lua

client = gs2('auth')

api_result = client.federation({
    originalUserId="user-0001",
    userId="user-0002",
    policyDocument="{\n  \"Version\": \"2016-04-01\",\n  \"Statements\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Actions\": [\n        \"Gs2Inbox:SendMessage\"\n      ],\n      \"Resources\": [\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001\",\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*\"\n      ]\n    }\n  ]\n}",
    timeOffset=nil,
    timeOffsetToken=nil,
})

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

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

```

**GS2-Script(Async)**
```lua

client = gs2('auth')

api_result_handler = client.federation_async({
    originalUserId="user-0001",
    userId="user-0002",
    policyDocument="{\n  \"Version\": \"2016-04-01\",\n  \"Statements\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Actions\": [\n        \"Gs2Inbox:SendMessage\"\n      ],\n      \"Resources\": [\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001\",\n        \"grn:gs2:ap-northeast-1:YourOwnerId:inbox:namespace-0001:*\"\n      ]\n    }\n  ]\n}",
    timeOffset=nil,
    timeOffsetToken=nil,
})

api_result = api_result_handler()  -- Call the handler to get the result

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

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

```




---

### issueTimeOffsetTokenByUserId

Issue a time offset token usable with the specified user ID

By passing a `time offset token` to APIs that operate with a specified user ID, API requests can be executed as if the specified user's current time had been virtually advanced.
For example, if a token is issued with timeOffset set to 86400 (24 hours), the server processes subsequent requests as if the current time were "current time + 24 hours".
This mechanism allows you to test time-dependent game features such as limited-time events, daily quests, and stamina recovery without waiting for actual time to pass.

If you want to use a time offset with APIs that use access tokens, you can specify timeOffsetToken when issuing the access token. Subsequent requests using that access token will then be processed with the same time offset applied.

Time offset tokens have an expiration period and become invalid one hour after issuance.
In addition, a token is associated with the user ID for which it was issued and cannot be used with requests for a different user ID.

This feature is primarily intended for testing and debugging purposes, such as verifying the behavior of scheduled events and time-limited content in advance.



#### Request

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| userId | string |  | ✓|  |  ~ 128 chars | User ID |
| timeOffset | int |  | | 0 | 0 ~ 315360000 | Time offset from the current time (number of seconds relative to the current time)<br>The time offset represents the difference from the current server time in seconds.<br>This value is used when in-game events or features need to operate according to a specific time. |
| timeOffsetToken | string |  | |  |  ~ 1024 chars | Time offset token |

#### Result

|  | Type | Description |
| --- | --- | --- |
| token | string | Time offset token<br>Issued time offset token. By passing this token to timeOffsetToken in subsequent requests, operations can be executed with the time shifted by the specified offset. |
| userId | string | User ID |
| expire | long | Expiration time<br>A timestamp indicating the expiration time of the token. When this date is reached, the token becomes invalid.<br>Unix time, milliseconds |

#### Implementation Example




**Go**
```go

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.IssueTimeOffsetTokenByUserId(
    &auth.IssueTimeOffsetTokenByUserIdRequest {
        UserId: pointy.String("user-0001"),
        TimeOffset: pointy.Int32(1000),
        TimeOffsetToken: nil,
    }
)
if err != nil {
    panic("error occurred")
}
token := result.Token
userId := result.UserId
expire := result.Expire

```

**PHP**
```php

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\IssueTimeOffsetTokenByUserIdRequest;

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

$session->open();

$client = new Gs2AuthRestClient(
    $session
);

try {
    $result = $client->issueTimeOffsetTokenByUserId(
        (new IssueTimeOffsetTokenByUserIdRequest())
            ->withUserId("user-0001")
            ->withTimeOffset(1000)
            ->withTimeOffsetToken(null)
    );
    $token = $result->getToken();
    $userId = $result->getUserId();
    $expire = $result->getExpire();
} catch (Gs2Exception $e) {
    exit("error occurred")
}

```

**Java**
```java

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.IssueTimeOffsetTokenByUserIdRequest;
import io.gs2.auth.result.IssueTimeOffsetTokenByUserIdResult;

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

try {
    IssueTimeOffsetTokenByUserIdResult result = client.issueTimeOffsetTokenByUserId(
        new IssueTimeOffsetTokenByUserIdRequest()
            .withUserId("user-0001")
            .withTimeOffset(1000)
            .withTimeOffsetToken(null)
    );
    String token = result.getToken();
    String userId = result.getUserId();
    long expire = result.getExpire();
} catch (Gs2Exception e) {
    System.exit(1);
}

```

**C#**
```csharp

using Gs2.Core;
using Gs2.Core.Model;
using Gs2.Core.Net;
using Gs2.Core.Exception;

var session = new Gs2RestSession(
    new BasicGs2Credential(
        "your client id",
        "your client secret"
    ),
    Region.ApNortheast1
);
yield return session.OpenAsync(r => { });
var client = new Gs2AuthRestClient(session);

AsyncResult<Gs2.Gs2Auth.Result.IssueTimeOffsetTokenByUserIdResult> asyncResult = null;
yield return client.IssueTimeOffsetTokenByUserId(
    new Gs2.Gs2Auth.Request.IssueTimeOffsetTokenByUserIdRequest()
        .WithUserId("user-0001")
        .WithTimeOffset(1000)
        .WithTimeOffsetToken(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;

```

**TypeScript**
```typescript

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.issueTimeOffsetTokenByUserId(
        new Gs2Auth.IssueTimeOffsetTokenByUserIdRequest()
            .withUserId("user-0001")
            .withTimeOffset(1000)
            .withTimeOffsetToken(null)
    );
    const token = result.getToken();
    const userId = result.getUserId();
    const expire = result.getExpire();
} catch (e) {
    process.exit(1);
}

```

**Python**
```python

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.issue_time_offset_token_by_user_id(
        auth.IssueTimeOffsetTokenByUserIdRequest()
            .with_user_id('user-0001')
            .with_time_offset(1000)
            .with_time_offset_token(None)
    )
    token = result.token
    user_id = result.user_id
    expire = result.expire
except core.Gs2Exception as e:
    exit(1)


```

**GS2-Script**
```lua

client = gs2('auth')

api_result = client.issue_time_offset_token_by_user_id({
    userId="user-0001",
    timeOffset=1000,
    timeOffsetToken=nil,
})

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

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

```

**GS2-Script(Async)**
```lua

client = gs2('auth')

api_result_handler = client.issue_time_offset_token_by_user_id_async({
    userId="user-0001",
    timeOffset=1000,
    timeOffsetToken=nil,
})

api_result = api_result_handler()  -- Call the handler to get the result

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

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

```




---

### getServiceVersion

Get microservice version



#### Request

Request parameters: None

#### Result

|  | Type | Description |
| --- | --- | --- |
| item | string | Version |

#### Implementation Example




**Go**
```go

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.GetServiceVersion(
    &auth.GetServiceVersionRequest {
    }
)
if err != nil {
    panic("error occurred")
}
item := result.Item

```

**PHP**
```php

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\GetServiceVersionRequest;

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

$session->open();

$client = new Gs2AuthRestClient(
    $session
);

try {
    $result = $client->getServiceVersion(
        (new GetServiceVersionRequest())
    );
    $item = $result->getItem();
} catch (Gs2Exception $e) {
    exit("error occurred")
}

```

**Java**
```java

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.GetServiceVersionRequest;
import io.gs2.auth.result.GetServiceVersionResult;

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

try {
    GetServiceVersionResult result = client.getServiceVersion(
        new GetServiceVersionRequest()
    );
    String item = result.getItem();
} catch (Gs2Exception e) {
    System.exit(1);
}

```

**C#**
```csharp

using Gs2.Core;
using Gs2.Core.Model;
using Gs2.Core.Net;
using Gs2.Core.Exception;

var session = new Gs2RestSession(
    new BasicGs2Credential(
        "your client id",
        "your client secret"
    ),
    Region.ApNortheast1
);
yield return session.OpenAsync(r => { });
var client = new Gs2AuthRestClient(session);

AsyncResult<Gs2.Gs2Auth.Result.GetServiceVersionResult> asyncResult = null;
yield return client.GetServiceVersion(
    new Gs2.Gs2Auth.Request.GetServiceVersionRequest(),
    r => asyncResult = r
);
if (asyncResult.Error != null) {
    throw asyncResult.Error;
}
var result = asyncResult.Result;
var item = result.Item;

```

**TypeScript**
```typescript

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.getServiceVersion(
        new Gs2Auth.GetServiceVersionRequest()
    );
    const item = result.getItem();
} catch (e) {
    process.exit(1);
}

```

**Python**
```python

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.get_service_version(
        auth.GetServiceVersionRequest()
    )
    item = result.item
except core.Gs2Exception as e:
    exit(1)


```

**GS2-Script**
```lua

client = gs2('auth')

api_result = client.get_service_version({
})

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

result = api_result.result
item = result.item;

```

**GS2-Script(Async)**
```lua

client = gs2('auth')

api_result_handler = client.get_service_version_async({
})

api_result = api_result_handler()  -- Call the handler to get the result

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

result = api_result.result
item = result.item;

```




---



