question

niardev avatar image
niardev asked

Proper Tutorial for implementing Google SignIn in Unity for Android AND iOS ?

Hello,

I'm developing a game in Unity for iOS and Android. I'd like to implement a Facebook and Google login options.

First problem is that the PlayFab tutorials are outdated.. Quite disappointing from such a big company but never mind.

I did a lot of searches and found multiple threads with parts of solutions but in the end it seems that Google Play Services only works on Android ?

But I don't want Google Play Services, only the Google Sign in feature. (unless it is mandatory, to be able to login via a Google account?)

To be honest I'm quite lost, I never did authentication before (except my own with basic duo email/password). I understood I had to fill some forms on Google Cloud Console to get specific IDs etc.. But I don't know what to do regarding Unity and Playfab.

What SDK should I download to be able to use Google Sign in for Android AND iOS ?

Even if I find the correct SDK to install, then what ? How to correctly implement this feature?
I tried to follow the Playfab tutorial for this but with HTML5 instead of Unity as it seemed less outdated.

But then I don't have the code example to implement this and/or I just don't understand..

- Is there any up-to-date tutorial for implementing a Google Sign In option in a Unity game for iOS and Android?

If you can share with me some proper documentation/video anything that can help me understand how to implement this I would be very glad.

Thanks

--

Useful search results :

Authentication
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JayZuo avatar image
JayZuo answered

Since you don't want Google Play Services, only the Google Sign in feature. Then please do not follow Setting up PlayFab authentication using Google Play games sign-in in Unity as it's using Google Play Games SDK.

To integrate PlayFab with Google Sign-In, please first follow Google's docs and mark sure a user can successfully sign in:

After this, please enable Server-Side Access by following Enabling Server-Side Access. In this step, you will use a Web application. This Web application's Client ID is your server client ID and also the one should be putted into PlayFab's Google Add-On page. For Client Secret, we should also use this Web application's Client secret.

After you've set up Google Add-On and got server auth code, you can then call LoginWithGoogleAccount.

As you can see, for PlayFab side, we will only need to setup the add-on properly and then call LoginWithGoogleAccount with the server auth code returned by Google. For an up-to-date tutorial in Unity, you may need to seek the help from Google.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

niardev avatar image niardev commented ·

Hello,

Thanks a lot for your answer.

So while trying to understand your reply and the documentation you linked, I have understood one thing : I have to log the user in via its Google account (the hard part, didn't find a working solution yet..), and at the same time request for a server auth code. Then if the user is successfully connected, call LoginWithGoogleAccount and give the server auth code in parameter.

Is that right?

0 Likes 0 ·
niardev avatar image
niardev answered

Hey,

So finally I've succeeded in implementing Google SignIn and have a ServerAuthCode in the result variable.

Then I do this :

PlayFabClientAPI.LoginWithGoogleAccount(
                new PlayFab.ClientModels.LoginWithGoogleAccountRequest()
                {
                    TitleId = PlayFabSettings.TitleId,
                    CreateAccount = true,
                    ServerAuthCode = task.Result.AuthCode
                }, OnPlayFabGoogleAuthComplete, OnPlayFabGoogleAuthFailed
            );

I already have confirmation success of login (and even a mail about login in with my Google Account) but when running LoginWithGoogleAccount() I get a

Google API error code: unauthorized_client detail: unauthorized

Title ID is set up in the GameManager Awake method. And of course when checking its value in the logs it is correct.

Same for Server Auth Code, each time I request one when Signing in I get one.

Copy/Pasted multiple time the Google OAuth Client Secret code and Google OAuth Client ID and I have even added these URIs on Google Cloud Console:

https://(my_title_id).playfabapi.com as "Authorized Javascript Origins"

and

https://oauth.playfab.com/oauth2/google as "Authorized Redirect URIs"

as mentioned here. Just in case, even though I'm not sure it is needed.

What can I do?

Thanks

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JayZuo avatar image JayZuo ♦ commented ·

This error you've mentioned is returned by Google. I'd suggest you recheck your project's the Credentials page in the API Console and make sure you have three clients (iOS, Android & Web application). In Google Add-On, please use the Web application's Id and secret.

0 Likes 0 ·
niardev avatar image niardev JayZuo ♦ commented ·

Hey, this is what I did but it didn't work. I think it could be because of the old token/new token thingy implemented by Google, not handled correctly in the code.

In the end I realized it was too risky implementing Google Account Sign In in a iOS app using a third party library (as Google isn't updating a Unity library anymore). Risking player loosing access to their game account if for any reason like an Apple or Google update makes the library obsolete is something I want to avoid for now.

Thanks for you help, too bad there isn't an official Unity Google SDK like Facebook.

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ commented ·

In the backend, we are using "https://www.googleapis.com/oauth2/v4/token" endpoint to get access token. You can test with the Server Auth Code you've got to see if it works.

curl -L -X POST 'https://www.googleapis.com/oauth2/v4/token?client_id={your-client-id}&client_secret={your-client-secret}&code={server auth code}&grant_type=authorization_code&redirect_uri=https://oauth.playfab.com/oauth2/google'
0 Likes 0 ·
sanglenoone avatar image
sanglenoone answered

Google update new client api, please update sdk and test it. It's not working right now

https://developers.google.com/identity/oauth2/web/guides/migration-to-gis#gapi-client-library

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.