유니티3D 프로그래밍

Firebase Auth 수업 내용 (21.06.30) 본문

Firebase/수업내용

Firebase Auth 수업 내용 (21.06.30)

tjdgus9955 2021. 7. 8. 11:27
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;

public class App : MonoBehaviour
{
    public Text txtVersion;
    public Text txtAuthenticate;

    void Start()
    {
        Screen.SetResolution(1080, 1920, true);
        this.txtVersion.text = Application.version;

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestIdToken().Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();

        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) => {

            this.txtAuthenticate.text = result.ToString();

            if (result == SignInStatus.Success) {
                var localUser = (PlayGamesLocalUser)Social.localUser;
                var googleIdToken = localUser.GetIdToken();
                Debug.LogFormat("googleIdToken: {0}", googleIdToken);

                Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
                Firebase.Auth.Credential credential =
                Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, null);
                auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                    if (task.IsCanceled)
                    {
                        Debug.LogError("SignInWithCredentialAsync was canceled.");
                        return;
                    }
                    if (task.IsFaulted)
                    {
                        Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                        return;
                    }

                    Firebase.Auth.FirebaseUser newUser = task.Result;
                    Debug.LogFormat("User signed in successfully: {0} ({1})",
                        newUser.DisplayName, newUser.UserId);
                });
            }
        });

    }
}

'Firebase > 수업내용' 카테고리의 다른 글

Firebase Analytics 수업 내용 (21.07.08)  (0) 2021.07.08