> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google 로그인에서 Play Games 로그인으로 마이그레이션 폴백

> Play Games Plugin for Unity 플러그인을 업그레이드한 후에도 여전히 Google Play Games ID를 사용하지 않는 플레이어를 위한 폴백 방법입니다.

# Play Games Plugin for Unity v0.11.x에서 LoginWithGoogleAccount 사용에 대한 해결 방법

이 문서에서는 Play Games Plugin for Unity 버전을 업그레이드한 후 **LoginWithGoogleAccount** API 사용 시 오류가 발생하는 경우의 해결 방법을 설명합니다.

이 오류는 [Play Games Plugin for Unity](https://github.com/playgameservices/play-games-plugin-for-unity)를 v0.11.x 이상 버전으로 업그레이드한 후 기존 플레이어가 [LoginWithGooglePlayGamesServices 사용으로 마이그레이션](/services/playfab/identity/player-identity/platform-specific-authentication/google-play-games-sign-in-migration-details#migration-steps)하지 않은 경우 발생합니다. 그 이유는 Google이 0.11.x 이상의 플러그인 버전에서 추가 스코프를 추가하는 기능을 제거했기 때문입니다.

이 해결 방법은 브라우저를 통해 로그인해야 하는 것이 플레이어 경험에 영향을 미칠 수 있으므로 폴백 대안으로 간주해야 합니다.

## 시작하기 전에

플러그인의 최신 버전을 사용할 때 인증을 수정하려면 다음의 상위 수준 단계를 따르세요.

1. Google OAuth2 API를 수동으로 호출
2. 브라우저 탭에서 플레이어 인증 수행
3. Android 딥 링크를 사용하여 게임으로 리디렉션 인증 코드 가져오기

## 권장 사항

플러그인의 0.10.x 버전을 계속 사용하는 동안 [사용자를 LoginWithGooglePlayGamesServices 사용으로 마이그레이션](/services/playfab/identity/player-identity/platform-specific-authentication/google-play-games-sign-in-migration-details#migration-steps)하세요. 플러그인의 0.11.x 이상 버전으로 업그레이드한 후 나머지 플레이어에 대한 폴백 방법으로 다음 단계를 사용하세요.

## 수정 단계

1. 딥 링크를 사용하여 게임에 Android 인텐트를 추가합니다. ([Unity - 매뉴얼: Android에서 딥 링크 (unity3d.com)](https://docs.unity3d.com/2021.2/Documentation/Manual/deep-linking-android.html)에서 조정한 단계)

   a. 프로젝트 창에서 **Assets > Plugins > Android**로 이동합니다.

   b. 새 파일을 생성하고 **AndroidManifest.xml**이라고 부릅니다. 애플리케이션을 빌드할 때 Unity가 이 파일을 자동으로 처리합니다.

   c. 다음 매니페스트 샘플을 새 파일에 복사하고, 데이터 요소를 앱의 URI로 업데이트한 다음 저장합니다. 적절한 데이터 태그를 빌드하는 방법에 대한 자세한 내용은 [이 문서](https://developer.android.com/guide/topics/manifest/data-element)를 참조하세요.

   ```xml theme={null}
   <?xml version="1.0" encoding="utf-8"?>
   <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
       <application>
       <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector">
           <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>

           <intent-filter android:autoVerify="true">
           <action android:name="android.intent.action.VIEW" />

           <category android:name="android.intent.category.DEFAULT" />
           <category android:name="android.intent.category.BROWSABLE" />

           <data
               android:scheme="https"
               android:host="mytestapp.com"
               android:path="/path1/subpath" />
           </intent-filter>
           
       </activity>
       </application>
   </manifest>
   ```

   d. intent-filter 태그에 **autoVerify** 속성이 있는지 확인합니다.

2. 딥 링크가 작동하려면 Android 12부터 Google에서는 개발자가 앱으로의 리디렉션이 성공하도록 잘 알려진 위치에 assetlinks.json 파일을 호스팅하도록 요구하고 있습니다.

   예를 들어, 리디렉션 URI가 [https://mytestapp.com/path1/subpath이면](https://mytestapp.com/path1/subpath이면) 유효한 assetlinks.json 파일을 [https://mytestapp.com/.well-known/assetlinks.json에](https://mytestapp.com/.well-known/assetlinks.json에) 호스팅해야 합니다. 그렇지 않으면 딥 링크가 작동하지 않고 앱으로 리디렉션되어 계속 진행할 수 없습니다.
   assetlinks.json 파일을 만드는 방법에 대한 자세한 내용은 [Android App Links 검증](https://developer.android.com/training/app-links/verify-android-applinks)을 참조하세요.

3. 딥 링크 처리를 게임에 추가합니다. ([Unity - 매뉴얼: 딥 링크 (unity3d.com)](https://docs.unity3d.com/2021.2/Documentation/Manual/deep-linking.html#using-deep-links)에서 조정한 단계)

   ```csharp theme={null}
   using GooglePlayGames;
   using GooglePlayGames.BasicApi;
   using PlayFab;
   using PlayFab.ClientModels;
   using System;
   using UnityEngine;
   using UnityEngine.UI;

   public class ProcessDeepLinkMngr : MonoBehaviour
   {
       public static ProcessDeepLinkMngr Instance { get; private set; }

       private void Awake()
       {
           if (Instance == null)
           {
               Instance = this;
               Application.deepLinkActivated += onDeepLinkActivated;
               if (!string.IsNullOrEmpty(Application.absoluteURL))
               {
                   // Cold start and Application.absoluteURL not null so process Deep Link.
                   onDeepLinkActivated(Application.absoluteURL);
               }

               DontDestroyOnLoad(gameObject);
           }
           else
           {
               Destroy(gameObject);
           }
       }

       private void onDeepLinkActivated(string url)
       {
           Debug.Log("Got Deeplink Activated: " + url);

           // Decode the URL to extract auth code. 
           string queryParams = url.Split("?"[0])[1];
           string[] keyValuePairs = queryParams.Split("&");
           string authCode = string.Empty;

           foreach (string s in keyValuePairs)
           {
               if (s.StartsWith("code"))
               {
                   authCode = s.Split("=")[1];
                   break;
               }
           }

           if (!string.IsNullOrEmpty(authCode))
           {
               // Call the LoginWithGoogleAccount using the auth code
               Debug.Log("Authenticating to PlayFab using LoginWithGoogleAccount...");

               // Make sure to unescape string
               authCode = Uri.UnescapeDataString(authCode);

               var request = new LoginWithGoogleAccountRequest
               {
                   ServerAuthCode = authCode,
                   CreateAccount = true,
                   TitleId = PlayFabSettings.TitleId
               };

               PlayFabClientAPI.LoginWithGoogleAccount(request,
                   (LoginResult result) => {
                       Debug.Log("PlayFab LoginWithGoogleAccount Success.");
                   },
                   (PlayFabError error) => {
                       Debug.Log("PlayFab LoginWithGoogleAccount Failure: " + error.GenerateErrorReport());
                   }
               );
           }
           else
           {
               Debug.Log("Error when getting Auth Code.");
           }
       }
   }
   ```

4. Google OAuth2 API로 브라우저를 실행하는 코드를 추가하고 플레이어가 브라우저를 통해 로그인할 수 있도록 합니다. 플레이어가 이미 브라우저에 로그인되어 있으면 원활하게 전환되지만, 그렇지 않으면 자격 증명을 입력해야 합니다.

   ```csharp theme={null}
   private string authorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
   private string redirectURI = "[APPLICATION-REDIRECT-URI]";
   private object clientID = "[WEB-APPLICATION-CLIENT-ID]";
   private string scopes = "profile";

   private void LaunchBrowserAuth()
   {
       string authorizationRequest = string.Format("{0}?response_type=code&scope={1}&redirect_uri={2}&client_id={3}",
               authorizationEndpoint,
               scopes,
               Uri.EscapeDataString(redirectURI),
               clientID);

       Application.OpenURL(authorizationRequest);
   }
   ```

   리디렉션 URI는 1단계에서 추가한 Android 인텐트 필터와 일치해야 합니다. 따라서 사용자가 인증을 완료하면 브라우저가 해당 리디렉션 URI로 이동하고, 브라우저는 사용자에게 애플리케이션으로 돌아갈지 여부를 묻습니다.

5. 이제 테스트할 준비가 되었습니다. 인증을 트리거하면 브라우저가 열리고 사용자는 그에 따라 로그인해야 합니다. 브라우저 데이터가 삭제되지 않는 한 이 단계는 일회성 프로세스입니다.

   <img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/google-unity/LWGA-fix-1.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=f6b510051e5e1f3456012cb7ed882174" alt="LoginWithGoogleAccount 사용 1단계" width="413" height="881" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/google-unity/LWGA-fix-1.png" />

6. 사용자가 인증을 완료한 후 브라우저는 어떤 애플리케이션이 리디렉션 URL을 열어야 하는지 묻습니다.

   <img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/google-unity/LWGA-fix-2.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=97d1b122fb3b35e0fa1cd97d2422200a" alt="LoginWithGoogleAccount 사용 2단계" width="412" height="879" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/google-unity/LWGA-fix-2.png" />

7. 이 작업은 애플리케이션으로 다시 이동하며, 리디렉션 URL의 쿼리 매개변수에서 코드를 얻고 LoginWithGoogleAccount를 호출할 수 있습니다.

   <img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/google-unity/LWGA-fix-3.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=5286049daf40d5f57ae37bb3dce570a8" alt="LoginWithGoogleAccount 사용 3단계" width="415" height="879" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/google-unity/LWGA-fix-3.png" />

8. 마지막으로, [마이그레이션 단계](/services/playfab/identity/player-identity/platform-specific-authentication/google-play-games-sign-in-migration-details#migration-steps)를 사용하여 마이그레이션할 수 없는 사용자에 대한 폴백 대안으로 이 방법을 사용하는 것이 좋습니다.

***어떤 사용자가 이미 LoginWithGooglePlayGamesServices 사용으로 마이그레이션되었는지 추적하고, 플러그인에서 제공하는 자동 로그인 메커니즘을 사용하는 것을 선호하며, 아직 마이그레이션되지 않은 사용자에 대해서만 이 해결 방법을 사용하는 것을 명심하세요.***
