유니티 파이어베이스 구글 로그인 - yuniti paieobeiseu gugeul logeu-in

  • 제품
  • 사용 사례
  • 가격 책정
  • 문서
    • 개요
    • 기초
    • 빌드
    • 출시 및 모니터링
    • 참여
    • 참조
    • 샘플
  • 커뮤니티
  • 지원
  • 콘솔로 이동

컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.

Google 로그인을 앱에 통합하여 사용자가 Google 계정으로 Firebase 인증을 받도록 설정할 수 있습니다.

시작하기 전에

Firebase 인증을 사용하려면 먼저 다음 작업이 필요합니다.

  • Unity 프로젝트를 등록하고 Firebase를 사용하도록 구성합니다.

    • Unity 프로젝트에서 현재 Firebase를 사용하고 있다면 이미 등록되어 Firebase용으로 구성된 것입니다.

    • Unity 프로젝트가 없는 경우 샘플 앱을 다운로드할 수 있습니다.

  • Firebase Unity SDK(특히 FirebaseAuth.unitypackage)를 Unity 프로젝트에 추가합니다.

Unity 프로젝트에 Firebase를 추가할 때 Firebase Console 및 열려 있는 Unity 프로젝트 모두에서 작업을 수행해야 합니다. 예를 들어 Console에서 Firebase 구성 파일을 다운로드한 후 이 파일을 Unity 프로젝트로 이동하는 작업이 필요합니다.

Firebase.Auth.FirebaseAuth 클래스 액세스

FirebaseAuth 클래스는 모든 API 호출에 대한 게이트웨이입니다. FirebaseAuth.DefaultInstance를 통해 액세스할 수 있습니다.

Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

Firebase 인증

  1. Android 및 iOS+ 안내에 따라 Google 로그인의 ID 토큰을 가져옵니다.
  2. 사용자가 정상적으로 로그인한 후에 액세스 토큰을 Firebase 사용자 인증 정보로 교환하고 Firebase 사용자 인증 정보를 사용해 Firebase에 인증합니다.Firebase.Auth.Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, googleAccessToken); 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.Auth.FirebaseUser 객체에서 사용자의 기본 프로필 정보를 가져올 수 있습니다.

    Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { string name = user.DisplayName; string email = user.Email; System.Uri photo_url = user.PhotoUrl; // The user's Id, unique to the Firebase project. // Do NOT use this value to authenticate with your backend server, if you // have one; use User.TokenAsync() instead. string uid = user.UserId; }
  • Firebase 실시간 데이터베이스와 Cloud Storage 보안 규칙의 auth 변수에서 로그인한 사용자의 고유 사용자 ID를 가져온 후 이 ID를 통해 사용자가 액세스할 수 있는 데이터를 관리할 수 있습니다.

인증 제공업체의 사용자 인증 정보를 기존 사용자 계정에 연결하면 사용자가 여러 인증 제공업체를 통해 앱에 로그인할 수 있습니다.

사용자를 로그아웃시키려면 SignOut()을 호출합니다.

auth.SignOut();

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2022-08-11 UTC.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"필요한 정보가 없음" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"너무 복잡함/단계 수가 너무 많음" },{ "type": "thumb-down", "id": "outOfDate", "label":"오래됨" },{ "type": "thumb-down", "id": "translationIssue", "label":"번역 문제" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"샘플/코드 문제" },{ "type": "thumb-down", "id": "otherDown", "label":"기타" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"이해하기 쉬움" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"문제가 해결됨" },{ "type": "thumb-up", "id": "otherUp", "label":"기타" }]