question

mihadelo avatar image
mihadelo asked

Google login

Hello, is it possible to Login player with google account, and with ServerAuthCode?

or

Execute cloud script when player is not logged in? And we would like to create our own login.

10 |1200

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

marcowilliamspf avatar image
marcowilliamspf answered

Today I've posted new instructions on how to setup google play signin

https://api.playfab.com/docs/tutorials/landing-players/sign-in-with-google

If you are unable to get the Auth Code from GPG, then check the following.

1> You have added the .GetServerAuthCode(false) to the builder

2> You are added to your google services as a tester

3> That you have the correct "resources" file (refer to the document above)

2 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.

pdaz avatar image pdaz commented ·

Thanks for updated manual. What helped me is adding BOTH Android and Web to Game Services.

0 Likes 0 ·
pdaz avatar image pdaz pdaz commented ·

So now I get Auth Code. If I try to login with Google it works fine, new account is creating. But when I try to link Google Account I see InvalidGoogleToken error.

I need to link Google to an old account.

Addon is set up correctly.

0 Likes 0 ·
brendan avatar image
brendan answered

To log in with a Google account, you would use LoginWithGoogleAccount, passing us the user's token.

Cloud Script was designed to be run in response to requests from the Client, though we will be providing a way to schedule Cloud Script calls for Segments in PlayStream shortly.

Could you clarify what you mean when you say you want to create your own login? For example, do you mean you have your own OIDC login system, and you want to use a token from it to sign into PlayFab?

10 |1200

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

PJ avatar image
PJ answered

Hi, actually there is second type of google token. Server Auth Code. Something like this...

        platform.GetServerAuthCode((status, authCode) => {
            if (authCode != null) { // this should be success
                lts = LoginTryState.Success;
                serverAuthCode = authCode;
            } else {
                if (status == CommonStatusCodes.Canceled || status == CommonStatusCodes.Interrupted || status == CommonStatusCodes.SignInRequired) {
                    lts = LoginTryState.Failed;
                } else {
                    lts = LoginTryState.Offline;
                }
            }

            Debug.Log("[BackEndManager] " + status + " Auth Code: " + authCode);
        });

Which can be exchanged for access token via https://accounts.google.com/o/oauth2/token. This token is returned by google game services plugin for unity. If you want to get the access token, another set of consent dialogs opens. Which if user denies access you are left logged in into game services but not in playfab(because token is missing).

We had to modify this plugin so its possible to add another permissions to initial login request. The only problem is we have to have external service for exchanging auth code for access token. If play fab would allow to have cloud scripts which can be executed by non authenticated users there would be no need to this type of external custom service. Exchange has to be done on external part because you need to make request to google with client_secret.

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.

brendan avatar image brendan commented ·

Actually, our tools team is working on an update to our Google authentication, specifically to address this.

1 Like 1 ·
brendan avatar image
brendan answered

Just making sure all the other threads on this topic have the updated info: We do now support the newer Google authentication (ServerAuthCode) process. Please see this post for more information: https://playfab.com/blog/setting-up-google-sign-in/.

10 |1200

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

pdaz avatar image
pdaz answered

Hi, the code that mentioned in article (https://blog.playfab.com/blog/setting-up-google-sign-in) is obsolete. I downloaded latest Google Play Games Plugin 0.9.39a. So far code has to be like this. But Auth code is always empty.

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().AddOauthScope("profile").Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();

Social.localUser.Authenticate((success) => {
	if(success)
	{
		Debug.Log("Auth was a success!");
		try
		{
			string AuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();


			Debug.LogFormat("AuthCode: {0}", AuthCode);


		}catch(System.Exception e)
		{
			Debug.Log("Error Getting Id Token: " + e.Message);
		}
	}
	else 
	{
		Debug.Log("False");
	}
});

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.

brendan avatar image brendan commented ·

This tutorial is our current documentation on the sign-in process using Google (https://api.playfab.com/docs/tutorials/landing-players/sign-in-with-google). Can you try using it and see if that helps?

0 Likes 0 ·
pdaz avatar image pdaz brendan commented ·

This doc was the first I read. Code is not working, they changed function GetServerAuthCode(), it no longer accepts arguments. I changed code on what I think it should be but it is not working. Tried it on empty Unity project. OAuth tried both: as Android and as web-app.

0 Likes 0 ·
brendan avatar image brendan pdaz commented ·

Thanks - we'll have our tools team take a look.

0 Likes 0 ·
marcowilliamspf avatar image
marcowilliamspf answered
In response to all of these posts and comments.

1> The blog post is not accurate any longer. It is depricated, and google changed the process. @pdaz implementation is correct. But there are a couple other factors you need to consider.

  • You must be a tester on the account in google services console
  • You must add the "Profile" to the scope .AddOauthScope("profile")
  • Call PlayGamesPlatform.Instance.GetServerAuthCode(); after you have used Social.localUser.Authenticate

2> We have updated the official document located here: https://api.playfab.com/docs/tutorials/landing-players/sign-in-with-google and provided a video. Granted the audio is broken, and I am working to make a new video where the audio is working. Might take me a few days to get to it though.

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.

pdaz avatar image pdaz commented ·

It started working properly only when I made it as singleton and added DontDestroyOnLoad(). It worked in 50% cases before it.

0 Likes 0 ·
pdaz avatar image pdaz commented ·

Additional info: if you start your app with Wi-Fi turned off Authentication will return success but auth code will always be empty. Don't know how to re-authenticate. I don't see apropreate function for this.

0 Likes 0 ·
Jaron Ray Hinds avatar image Jaron Ray Hinds commented ·

"Granted the audio is broken," #Classic

0 Likes 0 ·

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.