GS2-Auth SDK API リファレンス モデル AccessToken アクセストークン
ユーザー認証後に発行されるアクセストークンを管理するモデルです。 アクセストークンは、ユーザーがサービスにログインしている間、そのセッションの身元を証明するために使用されます。 トークンには有効期限が設定されており、期限切れになると再認証が必要になります。
型 有効化条件 必須 デフォルト 値の制限 説明 token string ✓ ~ 1024文字 アクセストークン userId string ✓ ~ 128文字 ユーザーID federationFromUserId string ~ 128文字 ユーザーID expire long ✓ 現在時刻からの差分(1時間) 有効期限 (UNIX時間 単位:ミリ秒) timeOffset int ✓ 0 ~ 31536000 現在時刻に対する補正値(現在時刻を起点とした秒数)
メソッド login 指定したユーザIDでGS2にログインし、アクセストークンを取得します 本APIは信頼出来るゲームサーバーから呼び出されることを想定しています。 ユーザIDの値の検証処理が存在しないため、クライアントから呼び出すのは不適切です。
Request 型 有効化条件 必須 デフォルト 値の制限 説明 userId string ✓ ~ 128文字 ユーザーID timeOffset int ✓ 0 ~ 31536000 現在時刻に対する補正値(現在時刻を起点とした秒数) timeOffsetToken string ~ 1024文字 タイムオフセットトークン
Result 型 説明 token string アクセストークン userId string ユーザーID expire long 有効期限 (UNIX時間 単位:ミリ秒)
実装例
Language:
Go
PHP
Java
C#
TypeScript
Python
GS2-Script
GS2-Script(Async) 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
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 )
-> withTimeOffsetToken ( 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 )
. withTimeOffsetToken ( 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 )
. 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 ;
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 );
}
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 )
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 [ 'message' ])
end
result = api_result.result
token = result.token ;
userId = result.userId ;
expire = result.expire ;
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 [ 'message' ])
end
result = api_result.result
token = result.token ;
userId = result.userId ;
expire = result.expire ;
loginBySignature 指定したユーザIDでGS2にログインし、アクセストークンを取得します ユーザIDの署名検証を実施することで、本APIはクライアントから呼び出しても安全です。
Request 型 有効化条件 必須 デフォルト 値の制限 説明 keyId string ✓ “grn:gs2:{region}:{ownerId}:key:default:key:default” ~ 1024文字 暗号鍵GRN body string ✓ ~ 1048576文字 アカウント認証情報の署名対象 signature string ✓ ~ 1024文字 署名
Result 型 説明 token string アクセストークン userId string ユーザーID expire long 有効期限 (UNIX時間 単位:ミリ秒)
実装例
Language:
Go
PHP
Java
C#
TypeScript
Python
GS2-Script
GS2-Script(Async) 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 ;
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 [ 'message' ])
end
result = api_result.result
token = result.token ;
userId = result.userId ;
expire = result.expire ;
federation 指定したユーザーIDを起点に別のユーザーIDとして振る舞うためのアクセストークンを取得します。 このアクセストークンを使ってトランザクションを発行する場合、トランザクションアクション内の #{userId} はフェデレーション先のユーザーIDに置き換えられ #{originalUserId} はフェデレーション元のユーザーIDに置き換えられます。
ポリシードキュメントを指定することで、フェデレーテッドユーザーとしてAPIを呼び出すにあたってクレデンシャルが持つ権限より厳しい制約を設定することができます。
Request 型 有効化条件 必須 デフォルト 値の制限 説明 originalUserId string ✓ ~ 128文字 ユーザーID userId string ✓ ~ 128文字 ユーザーID policyDocument string ~ 1048576文字 ポリシードキュメント timeOffset int ✓ 0 ~ 31536000 現在時刻に対する補正値(現在時刻を起点とした秒数) timeOffsetToken string ~ 1024文字 タイムオフセットトークン
Result 型 説明 token string アクセストークン userId string ユーザーID expire long 有効期限 (UNIX時間 単位:ミリ秒)
実装例
Language:
Go
PHP
Java
C#
TypeScript
Python
GS2-Script
GS2-Script(Async) 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
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 Gs2AccountRestClient (
$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" )
}
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 );
}
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.FederationRequest ;
using Gs2.Gs2Auth.Result.FederationResult ;
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 . 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 ;
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 );
}
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 )
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 [ 'message' ])
end
result = api_result.result
token = result.token ;
userId = result.userId ;
expire = result.expire ;
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 [ 'message' ])
end
result = api_result.result
token = result.token ;
userId = result.userId ;
expire = result.expire ;
issueTimeOffsetTokenByUserId 指定したユーザIDで使用可能なタイムオフセットトークンを取得します。
タイムオフセットトークンは アクセストークンを使用せず、ユーザーID を要求するAPIに指定することで擬似的に時間を進めてAPI処理を実行できます。 アクセストークンを使用するAPIでタイムオフセットを利用したい場合は、アクセストークンの発行時にタイムオフセットを指定することでリクエストごとにトークンを指定せずとも同等の処理を実行できます。
Request 型 有効化条件 必須 デフォルト 値の制限 説明 userId string ✓ ~ 128文字 ユーザーID timeOffset int ✓ 0 ~ 31536000 現在時刻に対する補正値(現在時刻を起点とした秒数) timeOffsetToken string ~ 1024文字 タイムオフセットトークン
Result 型 説明 token string タイムオフセットトークン userId string ユーザーID expire long 有効期限 (UNIX時間 単位:ミリ秒)
実装例
Language:
Go
PHP
Java
C#
TypeScript
Python
GS2-Script
GS2-Script(Async) 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
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 Gs2AccountRestClient (
$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" )
}
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 );
}
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.IssueTimeOffsetTokenByUserIdRequest ;
using Gs2.Gs2Auth.Result.IssueTimeOffsetTokenByUserIdResult ;
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 . 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 ;
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 );
}
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 )
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 [ 'message' ])
end
result = api_result.result
token = result.token ;
userId = result.userId ;
expire = result.expire ;
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 [ 'message' ])
end
result = api_result.result
token = result.token ;
userId = result.userId ;
expire = result.expire ;