Authentication トークンの処理
ProcessAuthenticationTokens
を使用して、Unity Authentication サービスアクセストークンを処理し、プレイヤーの認証を必要とする、ゲームに統合されている他の UGS SDK で使用できるようにします。アクセストークンには期限があるため、アクセストークンを手動で更新し、新しいアクセストークンを使用して ProcessAuthenticationTokens
を呼び出す必要があります。ProcessAuthenticationTokens
の呼び出しには、アクセストークンとセッショントークンの両方を使用できます。Unity Authentication SDK は、期限が切れる前にアクセストークンを更新し、プレイヤーのセッションをアクティブに保ち、キャッシュされたプレイヤーのサインイン を有効にします。
using Unity.Services.Authentication;
void SignUserWithCustomTokenWithAutoRefresh()
{
try
{
// Check if a cached player already exists by checking if the session token exists
if (AuthenticationService.Instance.SessionTokenExists)
{
// This call will sign in the cached player.
await AuthenticationService.Instance.SignInAnonymouslyAsync();
Debug.Log("Cached user sign in succeeded!");
}
else
{
var userTokens = // Fetch the user tokens using your method calls
AuthenticationService.Instance.ProcessAuthenticationTokens(userTokens.AccessToken, userTokens.SessionToken)
}
// Shows how to get the playerID
Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}");
}
catch (AuthenticationException ex)
{
// Compare error code to AuthenticationErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (RequestFailedException ex)
{
// Compare error code to CommonErrorCodes
// Notify the player with the proper error message
Debug.LogException(ex);
}
catch (Exception ex) {
// Handle exceptions from your method call
Debug.LogException(ex);
}
}
サンプルコードはメソッドのみであり、クラスではありません。