question

John Bennett avatar image
John Bennett asked

Unity - Playfab / Google Signin - Windows Build?

Hello all! Wondering if someone can help or at least point me in the right direction, sorry if this should be posted in the /r/unity sub instead just let me know otherwise.

I currently have playfab setup on my game where you can login to facebook and google play games with playfab but google play games (GPG - I'll call it this from now on) isn't available outside of mobile so I'm trying to figure out how to get a login working with a windows build then I can work on the facebook version.

So far logging in to GPG with playfab goes something like:

//Get Auth Code
var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();
PlayGamesPlatform.Instance.Authenticate(PlayGamesAuthenticateResult)


And PlayGamesAuthenticateResult runs


PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest() {
    TitleId = PlayFabSettings.TitleId,
    ServerAuthCode = serverAuthCode, 
    CreateAccount = true
}



Since GPG isn't available then you can't call GetServerAuthCode from the PlayGamePlatform reference to get the auth code.

Now I always thought my googlefu was pretty decent but everyone asking this question or something similar that could find ends up pointing to this link which doesn't massively answer the question:

Setting up PlayFab authentication using Google and HTML5


This shows that they still call the LoginWithGoogleAccount method but within HTML5 and instead getting the auth code from:

  var accessToken = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse(true).access_token;


Sorry for being dense here but how do I go about implementing this? I wanted to set another scripting define symbol to have an "if UNITY\_WINDOWS" then login etc but does this mean there is a way to call a set bunch of HTML5 code from within my C# script to get at least the auth code or do I instead have to implement some kind of manual API plugin/method or something?


Thanks in advance! This has been doing my head in for a while now :(

apisunity3dAuthentication
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

From Google's documentation, we can see there are Google Sign-In for Android, iOS, TVs and Devices, Web.

However, there is no support for Windows. From what I can see you will need to build your own authentication solution for Windows with Google's OAuth 2.0 APIs. For more details, please see OAuth 2.0 for Mobile & Desktop Apps | Google Identity.

Once you can get the access token, you can then modify our SDK to LoginWithGoogleAccount like "Authentication - Login With Google Account" docs and Unity SDK are missing the "AccessToken" variable - Playfab Community. Although AccessToken is not recommended, it should be able to work.


41knb.png (40.0 KiB)
10 |1200

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

Seth Du avatar image
Seth Du answered

As far as I know Google Play Service is specific to Android devices that implemented with Google Play Service. At Google official documentation website, it is recommended by Google to use Google Sign-In if there is a backend server.

Google Play login and Google sign-in are separate, and please consult Google support to know if it is possible to use Google Play Service on Windows. The PlayFab document you have posted is for Google Sign-in instead of Google Play Sign-in. PlayFab cannot interfere the process of getting a server auth code, and its API simply authenticates the request content with Google server.

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.

John Bennett avatar image John Bennett commented ·

Correct that's entirely why I linked it because its NOT Google Play Services that I need to use with a Windows build as per what I wrote in the original post.

I have completed the signin method for Android by using the "Google Play Services".

I am now after help signing into Google and playfab WITHOUT Google Play Services I.e the windows build option in Unity. In the linked document the sample shows how to get the required auth code using HTML5 to then sign into playfab, so how do I get this to work in a C# enviroment.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ John Bennett commented ·

We are not expert in Google Sign-in implementation, and since there is only HTML5 implementation tutorial on PlayFab, I suggest finding more details in Unity or Google community. As I have mentioned, PlayFab cannot interfere the process of getting a server auth code. Hopefully, this thread may help -- Login using Google OAuth 2.0 with C# - Stack Overflow.

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.