Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

822
Views
How to Access Auth Token in Unity with GameCenter Firebase Authentication

I would like to add the GameCenter Authentication with Firebase to my Unity Game. But in the documentation there isn't the GameCenter part (only Play Games one). I already achieved the "Unity part":

public static void GameCenterAuth()
    {
        GameCenterPlatform.ShowDefaultAchievementCompletionBanner(true);
        Social.localUser.Authenticate (GameCenterProcessAuth);
    }

    static void GameCenterProcessAuth(bool success)
    {
        if (success) 
        {
            Social.ReportProgress("Achievement01", 100, (result) => {
            Debug.Log(result ? "Reported achievement" : "Failed to report achievement");
        });

        }
        else
        {
            Debug.Log ("Failed to authenticate");
        }
    }

But it misses the link with Firebase. For this I need to get the access token of GameCenter but like the doc doesn't exist, I don't know how to achieve this.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Hopefully there aren't many holes in the Unity documentation, but when you do find one you can often find sample code in the Unity Quickstarts (as these are also used to validate changes to the Unity SDK).

From UIHandler.cs in the Auth quickstart:

    public Task SignInWithGameCenterAsync() {
      var credentialTask = Firebase.Auth.GameCenterAuthProvider.GetCredentialAsync();
      var continueTask = credentialTask.ContinueWithOnMainThread(task => {
        if(!task.IsCompleted)
          return null;

        if(task.Exception != null)
          Debug.Log("GC Credential Task - Exception: " + task.Exception.Message);

        var credential = task.Result;

        var loginTask = auth.SignInWithCredentialAsync(credential);
        return loginTask.ContinueWithOnMainThread(HandleSignInWithUser);
      });

      return continueTask;
    }

What's weird about GameCenter is that you don't manage the credential directly, rather you request it from GameCenter (Here's PlayGames by comparison, which you have to cache the result of Authenticate manually).

So in your code, I'd go into the if (success) block and add:

GameCenterAuthProvider.GetCredentialAsync().ContinueWith(task => {
    // I used ContinueWith
    // be careful, I'm on a background thread here.
    // If this is a problem, use ContinueWithOnMainThread
    if (task.Exception != null) {
        FirebaseAuth.GetInstance.SignInWithCredentialAsync(task.Result).ContinueWithOnMainThread(task => {
            // I used ContinueWithOnMainThread
            // You're on the Unity main thread here, so you can add or change scene objects
            // If you're comfortable with threading, you can change this to ContinueWith
        });
    }
});
over 4 years ago · Santiago Trujillo Report

0

https://firebase.google.com/docs/auth/ios/game-center This might answer your question. You may have to implement this feature in XCode when you export the project from unity

over 4 years ago · Santiago Trujillo Report

0

To complete Patrick's answer I found the machahamster GitHub repo where they use the Game Center Auth with Firebase on Unity. If it can helps someone: https://github.com/google/mechahamster/blob/b5ab9762cc95a2a36156d0cbd1dc08fb767c4080/Assets/Hamster/Scripts/Menus/GameCenterSignIn.cs#L45

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!