커스텀 ID 로그인
Provide a Custom ID sign-in option to enable players to authenticate using your custom identity system in your game.
읽는 시간 1분최근 업데이트: 한 달 전
최소 SDK 버전: 3.1.0
이 문서에서는 게임에서 커스텀 토큰으로 플레이어 인증을 설정하는 다음 시나리오에 대해 설명합니다.- 커스텀 ID 제공업체 로그인을 설정합니다.
- 기존 사용자를 로그인시키거나 새 사용자를 생성합니다.
커스텀 ID 로그인 설정
-
다음과 같은 방법으로 Unity의 ID 제공업체로 커스텀 ID를 추가합니다.
- Unity 에디터 메뉴에서 Edit > **Project Settings…**로 이동한 후, 내비게이션 메뉴에서 Services > Authentication을 선택합니다.
- ID Providers를 Custom으로 설정한 후, Add를 선택합니다.
- 서비스 계정을 생성하고 프로젝트 역할 **플레이어 인증 토큰 발급자**를 추가합니다.
기존 플레이어 로그인 또는 신규 플레이어 생성
-
커스텀 ID 인증을 사용해 플레이어를 로그인하려면 자체 게임 서버에 Unity Authentication 서비스 액세스 토큰과 세션 토큰을 요청해야 합니다.
사용자 게임 서버:
- 토큰 교환 API를 호출하여 상태 비보존 토큰을 검색합니다.
- 커스텀 ID API로 로그인을 호출합니다.
-
게임 서버에서 가져온 액세스 토큰과 세션 토큰을 사용해 API를 호출합니다.
ProcessAuthenticationTokens
인증 토큰 처리
ProcessAuthenticationTokensProcessAuthenticationTokensProcessAuthenticationTokens샘플 코드는 클래스가 아니라 메서드뿐임을 유의해 주십시오.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); }}