Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Chris B. · Dec 19, 2017 at 12:08 AM · Authentication

Firebase, Google Login, and Unity

I am adding Google login to my Unity project (note, not the Google play sdk, just the login). I have almost everything set up and used Firebase to generate my json file for my app. I'm able to get logged in to Google and I pass the server token to Playfab using loginWithGoogle, but I get the mismatch redirect_uri error.

So I read over this https://api.playfab.com/docs/tutorials/landing-players/sign-in-with-google, but since I'm going through the Google sign in on Firebase, the interface is a little different.

I tried adding the oauth.playfab.com to the authorized domain section, but I am still getting the same error. Anybody have experience with using Firebase and setting up Google sign in through that and know what step I'm missing?

I'm not actually going through Firebase authentication, I just setup the Google Login through it and got all the stuff setup there.

Comment
aboulianne

People who like this

1 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by pfnathan · Dec 19, 2017 at 12:15 AM

Unfortunately, we do not support Firebase yet, so the method which you have used will not work.

For your reference, we recommend reviewing our 2 part video tutorials which available on Youtube:

https://www.youtube.com/results?search_query=Playfab+google

Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chris B. · Dec 19, 2017 at 06:57 AM 1
Share

Ah, ok. Well, maybe Playfab will support Firebase sometime in the near future. I was trying to avoid using Google Play Games, and the straight up Google Log in was nice since it didn't add the other stuff.

Thanks for the help.

Edit: Ok, actually got this to work with Firebase. I had to add the oauth to the Google sign in credentials. I then tried to log in and it created my account and shows it's linked to Google. So it appears to be working, unless there is something I missed somewhere. If for some reason this is incorrect on Playfabs side, please let me know, but otherwise, it seems right?

avatar image pfnathan ♦ · Dec 19, 2017 at 06:28 PM 0
Share

Thanks for the update, the problem before was that the auth ticket Firebase provided did not grant the right ticket. Google may have fixed this issue recently.

Would you mind sending us your code sample so that we can validate that it is working and incorporate it into our docs?

avatar image

Answer by Chris B. · Dec 20, 2017 at 06:35 AM

Sure thing! That way I know I didn’t do anything odd when setting this up.

I’m using this sdk in Unity 2017.2. https://github.com/googlesamples/google-signin-unity

I then went to Firebase and created a new project. Under authentication -> sign in, you can add Google as an option. Where you enable it, there is a section for Web SDK configuration. This is where I got the web client ID and the Web client secret.

Also on this screen is a section that says Whitelist client IDs from external projects. There is a question mark next to it that includes a link to the Google API Console. Going there I get taken to the credentials.

Under there is a section for OAuth 2.0 client IDs. The web one should be listed there (and Android one if you set that up). There is a pencil to edit this.

This part I hope is correct. There is an Authorized redirect URIs in that section. I added https://oauth.playfab.com/oauth2/google to there.

Also need to get the sha1 key, which this explains how https://developers.google.com/android/guides/client-auth

This is used for the Android setup and will require your keystore from the Android build.

Once all that was setup, I was able to get the google-services.json file on Firebase. This included everything I needed and I added it to my Unity project.

The login code I used below.

private GoogleSignInConfiguration gConfig;

private void Awake()
{
//googleWebId is the web client ID from above
   gConfig = new GoogleSignInConfiguration
   {
      WebClientId = googleWebId,
      RequestIdToken = true
   };
}

public void LoginWithGoogle()
{
   GoogleSignIn.Configuration = gConfig;
   GoogleSignIn.Configuration.UseGameSignIn = false;
   GoogleSignIn.Configuration.RequestIdToken = true;
   GoogleSignIn.Configuration.RequestAuthCode = true;
        
   Debug.Log("Google Sign In");

   GoogleSignIn.DefaultInstance.SignIn().ContinueWith(GoogleSignInComplete);
}

internal void GoogleSignInComplete(Task<GoogleSignInUser> task)
{
   if (task.IsFaulted)
   {
      using (IEnumerator<System.Exception> enumerator =
                  task.Exception.InnerExceptions.GetEnumerator())
      {
         if (enumerator.MoveNext())
         {
            GoogleSignIn.SignInException error = (GoogleSignIn.SignInException)enumerator.Current;
            Debug.Log("Got Error: " + error.Status + " " + error.Message);
         }
         else
         {
            Debug.Log("Got Unexpected Exception?!?" + task.Exception);
         }
      }
   }
   else if (task.IsCanceled)
   {
      Debug.Log("Canceled");
   }
   else
   {
      Debug.Log("IDTOKEN " + task.Result.IdToken);
      Debug.Log("AUTHCODE " + task.Result.AuthCode);
      Debug.Log("Welcome: " + task.Result.DisplayName + "!");
      PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest
      {
         ServerAuthCode = task.Result.AuthCode,
         CreateAccount = true,
         TitleId = playFabGameID

      }, (result) =>
      {
         print("PlayfabResults " + result.PlayFabId);
      }, (error) =>
      {
         print("ERROR " + error.ErrorMessage + " :::: " + error.ErrorDetails);
      });      
   }
}

Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pfnathan ♦ · Dec 20, 2017 at 06:15 PM 0
Share

Thank you for sharing sample code.

avatar image

Answer by sauliusvince · Apr 26 at 12:13 AM

Hello, I'm been trying for a week to do the same thing. Login via firebase and then when I extract AuthCode, I want to connect with google to the Playfab. Google side works, ask for email selection and retrieves server auth. However, when I try to login with playfab I get error: "unauthorized_client details".

Don't remember what I did, but everything is working.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    Related Questions

    PlayFab Authentication to Photon Error 2 Answers

    Email registration across different titles 1 Answer

    Unreal Engine 4 "Unable to contact server" 2 Answers

    Automatically Login to Playfab account on game reboot? 1 Answer

    Facebook Login: Error when logging in a test account 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges