인증 토큰 처리
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);
}
}
샘플 코드는 클래스가 아니라 메서드뿐임을 유의해 주십시오.