Steam

최소 SDK 버전: 2.0.0

이 문서에서는 게임에서 Steam 계정을 사용해 플레이어의 인증을 설정하는 다음 시나리오에 대해 설명합니다.

  • Steam 계정 로그인 설정
  • 기존 사용자 로그인 또는 새 사용자 생성
  • 사용자를 익명 로그인에서 Steam 계정을 통한 플랫폼 로그인으로 업데이트

게임에서 플레이어에게 Steam 로그인 옵션을 제공하려면 SteamWorks Partner Portal에서 앱을 생성하고 Steamworks.Net SDK를 설치해 사용자를 로그인 처리하고 세션 티켓을 가져오십시오.

Steam 계정 로그인 설정

  1. 앱을 생성하고 Steamworks 기술 자료에 따라 앱 ID를 확인합니다.

  2. 웹 API 키를 사용한 인증(영문) 기술 자료에 따라 퍼블리셔 웹 API 키를 생성합니다.

  3. Unity용 SDK 설치 지침에 따라 SteamWorks.Net SDK를 설치합니다.

    1. 프로젝트의 Assets/ 폴더에 SteamWorks.Net SDK를 복사합니다.
    2. Unity 프로젝트 루트에 있는 steam_appid.txt를 열고 480을 앱 ID로 대체합니다.
    3. 씬 내 게임 오브젝트에 Steam Manager 게임 컴포넌트를 추가합니다. 이 컴포넌트가 Steam 라이브러리를 초기화합니다.
    4. 테스트를 진행하려면 Steam이 설치되어 있고 로그인한 상태여야 합니다. Steam 사용자의 라이브러리에 개발 중인 게임이 표시됩니다.
  4. Unity Authentication의 ID 제공업체를 Steam으로 설정합니다.

    1. Unity 에디터 메뉴에서 Edit > **Project Settings…**로 이동한 후, 내비게이션 메뉴에서 Services > Authentication을 선택합니다.
    2. ID ProvidersSteam로 설정한 후, Add를 선택합니다.
    3. App ID 텍스트 필드에 앱 ID를 입력합니다.
    4. Key 텍스트 필드에 퍼블리셔 웹 API 키를 입력한 후, Save를 선택합니다.

    (선택 사항) 데모, 플레이테스트, 알파 빌드에 대한 추가 앱 ID를 추가합니다. 계속해서 Authentication Settings에서 수행합니다.

    1. Additional App ID 옆의 화살표를 선택합니다.
    2. 펼쳐진 보기의 하단에서 Add App ID를 선택합니다.
    3. 앱 ID설명을 입력합니다.
    4. Save를 선택합니다.
  5. 아래 샘플 코드를 따라 Steam 로그인을 구현합니다. GetAuthTicketForWebApi 기술 자료를 참고하십시오. Unity Authentication SDK는 Steam 세션 티켓만 지원합니다. 암호화된 애플리케이션 티켓은 지원하지 않습니다.

중요: Steam SDK가 제공하는 OnAuthCallback에 등록해야 합니다. 그래야만 올바르게 인증 티켓을 확인할 수 있습니다. 자세한 내용은 여기를 참고하십시오. 아래 코드는 Steam 인증의 모범적인 예시입니다. 중요: Unity Player 인증은 5에서 30 사이의 영숫자를 포함하는 문자열만 ID 필드로 허용하므로 동일한 요구 사항에 따라 동일한 문자열을 사용해 티켓을 요청해야 합니다.

Callback<GetTicketForWebApiResponse_t> m_AuthTicketForWebApiResponseCallback;
string m_SessionTicket;
string identity = "unityauthenticationservice"

void SignInWithSteam()
{
    // It's not necessary to add event handlers if they are 
    // already hooked up.
    // Callback.Create return value must be assigned to a 
    // member variable to prevent the GC from cleaning it up.
    // Create the callback to receive events when the session ticket
    // is ready to use in the web API.
    // See GetAuthSessionTicket document for details.
    m_AuthTicketForWebApiResponseCallback = Callback<GetTicketForWebApiResponse_t>.Create(OnAuthCallback);

    SteamUser.GetAuthTicketForWebApi(identity);
}

void OnAuthCallback(GetTicketForWebApiResponse_t callback)
{
    m_SessionTicket = BitConverter.ToString(callback.m_rgubTicket).Replace("-", string.Empty);
    m_AuthTicketForWebApiResponseCallback.Dispose();
    m_AuthTicketForWebApiResponseCallback = null;
    Debug.Log("Steam Login success. Session Ticket: " + m_SessionTicket);
    // Call Unity Authentication SDK to sign in or link with Steam, displayed in the following examples, using the same identity string and the m_SessionTicket.
}

참고: 아래 코드 예시에서는 GetAuthTicketForWebApi 메서드를 사용하여 플레이어의 Steam 세션 티켓을 이미 보유하고 있으며 티켓 발급을 위해 동일한 identity 파라미터를 전달했다고 가정합니다.

기존 플레이어 로그인 또는 신규 플레이어 생성

SignInWithSteamAsync 메서드를 사용하여 다음 중 하나를 수행할 수 있습니다.

  • Steam 자격 증명을 사용해 새 Unity Authentication 플레이어 생성
  • Steam 자격 증명을 사용해 기존 플레이어 로그인

프로젝트에서 자격 증명과 연결된 Unity Authentication 플레이어가 존재하지 않는 경우, SignInWithSteamAsync가 새 플레이어를 생성합니다. 프로젝트에서 자격 증명과 연결된 Unity Authentication 플레이어가 존재하는 경우, SignInWithSteamAsync가 해당 플레이어의 계정으로 로그인합니다. 이 기능은 캐시된 플레이어를 고려하지 않으며, SignInWithSteamAsync가 캐시된 플레이어를 대체합니다.

async Task SignInWithSteamAsync(string ticket, string identity)
{
    try
    {
        await AuthenticationService.Instance.SignInWithSteamAsync(ticket, identity);
        Debug.Log("SignIn is successful.");
    }
    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);
    }
}

플레이어를 익명 로그인에서 Steam 계정 로그인으로 업데이트

익명 인증을 설정한 후, 플레이어가 Steam 계정을 생성하고 Steam 계정을 통해 로그인하도록 업그레이드하려는 경우, 게임이 플레이어에게 Steam 로그인 창을 표시하고 Steam에서 세션 티켓을 가져와야 합니다. 그런 다음 LinkWithSteamAsync API를 호출해 플레이어를 Steam 세션 티켓에 연결합니다.

SDK에 캐시된 플레이어가 존재하는 경우, 캐시된 플레이어를 Steam 계정에 연결할 수 있습니다.

  1. SignInAnonymouslyAsync를 사용해 캐시된 플레이어의 계정에 로그인합니다.
  2. LinkWithSteamAsync를 사용해 캐시된 플레이어의 계정을 Steam 계정에 연결합니다.

캐시된 플레이어에 대한 자세한 내용은 캐시된 사용자 로그인 섹션을 참고하십시오.

async Task LinkWithSteamAsync(string ticket, string identity)
{
    try
    {
        await AuthenticationService.Instance.LinkWithSteamAsync(ticket, identity);
        Debug.Log("Link is successful.");
    }
    catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked)
    {
        // Prompt the player with an error message.
        Debug.LogError("This user is already linked with another account. Log in instead.");
    }
    catch (Exception ex)
    {
        Debug.LogError("Link failed.");
        Debug.LogException(ex);
    }
}

플레이어가 로그인하거나 새 플레이어 프로필을 생성해 Steam 로그인을 트리거하고 동일한 ID 파라미터를 사용하여 Steam 액세스 토큰을 받은 경우, 다음 API를 호출하여 플레이어를 인증합니다.

async Task SignInWithSteamAsync(string ticket, string identity)
{
    try
    {
        await AuthenticationService.Instance.SignInWithSteamAsync(ticket, identity);
    }
    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);
    }
}

추가 앱 ID를 위해 기존 플레이어로 로그인 또는 새 플레이어 생성

동일한 SignInWithSteamAsync 메서드를 사용하여 플레이어를 추가 앱 ID(예: Demo, PlayTest, Alpha)로 로그인합니다.

참고: 아래 코드 예시에서는 GetAuthTicketForWebApi 메서드를 사용하여 플레이어의 Steam 세션 티켓을 이미 보유하고 있으며 티켓 발급을 위해 동일한 identity 파라미터를 전달했다고 가정합니다.

중요: 플레이어는 동일한 프로젝트의 모든 앱 ID에 대해 동일한 Unity Authentication 플레이어 ID를 가지므로, 신중하게 판단하여 플레이어 데이터(예: Economy, Cloud Save)의 범위를 각 앱 ID로 유지하고 프로덕션 데이터와 비프로덕션 데이터가 혼합되지 않도록 서로 다른 환경을 설정해야 합니다.

async Task SignInWithSteamAsync(string ticket, string identity, string appId)
{
    try
    {
        await AuthenticationService.Instance.SignInWithSteamAsync(ticket, identity, appId);
        Debug.Log("SignIn is successful.");
    }
    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);
    }
}

Steam 로그인 인증 구현

Steam 세션 티켓을 사용해 Steam 계정으로 로그인하거나 연결할 수 있습니다. 플레이어를 로그인 처리하려면 SignInWithSteamAsync(string ticket, string identity) API를 호출합니다.

Unlink Steam account#
Use the `UnlinkSteamAsync` API so your players can unlink their Steam account. Once unlinked, if their account isn’t linked to any additional identity, it transitions to an anonymous account.

async Task UnlinkSteamAsync(string idToken)
{
   try
   {
       await AuthenticationService.Instance.UnlinkSteamAsync(idToken);
       Debug.Log("Unlink is successful.");
   }
   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);
   }
}