question

John Bennett avatar image
John Bennett asked

Google Windows Login (NOT GPG/Google Play as this is unavailable in Windows) - invalidGoogleToken

Hi all,


Hopefully someone can point me in the right direction here, I'm attempting to log into Playfab using the auth code retrieved from an async call, the flow is as follows:

1. Click login to google.

2. Unity begins to listen for the response and opens a google login browser session.

3. User clicks email/signs into email they want.

4. This response is returned to Unity with an auth code.

5. I have then attempted to use:

PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest()
{
    TitleId = PlayFabSettings.TitleId,
    ServerAuthCode = returnedWindowsGoogleAuthCode,

    CreateAccount = true,
}, OnPlayfabGooglePlayAuthComplete, OnPlayfabGooglePlayAuthFailed);

6. This then fails with "invalidGoogleToken"

Now from what I've read across previous users is that this token is basically "used" by the time I am calling LoginWithGoogleAccount? Is this either the wrong approach by calling this after? (I feel I'm super close with this)

If I were to get the email back in the original response would I just be able to pass through to a different method to complete the login to Playfab?

To give you an idea of (nearly the exact code but altered to work in Unity)
Link:-> Googles Desktop Sample Main Code Chunk

The method "button_Click" is ran which fires the request, Unity begins listening for the google response at line 72, the auth code is then output to logs at line 129, this auth code is what I have then been passing in to LoginWithGoogleAccount which then results in the fail, this then runs a request for user information so as an alternative if I managed to get the email back in this response is there another method I can use with the email to log the user in?

I know this was alot but thanks in advance!

apisunity3dAuthenticationwindows
5 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 ·

Not sure why I can't edit the original post, not sure why I thought I could just login with the email without a password etc, but if anyone could still give me guidance on how to proceed after getting an auth code that would be great, I can't see how you could rerequest an auth code without needing to reopen a browser and run through the whole same process again etc.

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

May I know the code that you get the server auth code? Please remember to remove any confidential information.

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

Yes it is almost 100% the same as the one above (slight modifications to make it work in Unity but its entirely the same)

which is this one ->code <-

Those credentials in this are the sample ones of course, the auth code is extracted from the response at line 129 in the above link I'm then using that auth code which looks/has the exact same structure as the ones that are returned when using the android GPG version.

0 Likes 0 ·
John Bennett avatar image John Bennett John Bennett commented ·
{"code":400,
 "status":"BadRequest",
 "error":"InvalidGoogleToken",
 "errorCode":1026,"errorMessage":"Google API error code: invalid_grant details: Missing code verifier."}

So I'm back to square one with the same error without a clue on how to proceed.

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

Just to add to my previous comments, if I remove the call to line 132 (I read somewhere that at that point I am swapping the auth code for a token and thus the auth code will no longer work?) and then call PlayFabClientAPI.LoginWithGoogleAccount with the auth code I am presented with:

PlayFabError error:

error.GetHashCode(): 2051826304

error.Error: InvalidGoogleToken

error.ErrorMessage: invalid_grant details: Missing code verifier.

error.ErrorDetails: null


Hopefully this may help you guide me?

0 Likes 0 ·
JayZuo avatar image
JayZuo answered

Please understand that the ServerAuthCode is not the authorization code you've got in OAuth 2.0 flow. The ServerAuthCode comes from the Google Sign-In server-side flow, which differs from the OAuth 2.0 for Web server applications flow. For more details, please see Google Sign-In for server-side apps. However, Google does not provide Google Sign-In for Desktop, I'm afraid there is no way to get the ServerAuthCode for Desktop Apps.

In this situation, you may try with AccessToken instead of ServerAuthCode like in Setting up PlayFab authentication using Google and HTML5. While using AccessToken, you will need to modify PlayFab's SDK like https://community.playfab.com/answers/40300/view.html. Although AccessToken is deprecated and not recommended, it should still be able to work.

To get the AccessToken for Desktop Apps, please refer to OAuth 2.0 for Mobile & Desktop Apps.

Besides, in the definition of LoginWithGoogleAccountRequest, it explains why PlayFab uses ServerAuthCode instead of AccessToken.

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 answered

Awesome, thank you @Jay Zuo and @SethDu for your time and patience in this issue (It wouldn't let me directly reply to your comment), this does indeed work! While the AccessToken being made deprecated can I assume this will be removed at some point in the future by yourselves?

The reason I ask is because instead of deprecating it, why not instead have this as an extra so to speak? because this does indeed work as a solution for a "Google + Playfab login + Unity Standalone Desktop Builds" especially as there seems to be no other solutions (for Unity desktop + Playfab + Google)


The solution I've used uses your link to OAuth 2.0 for Mobile & Desktop Apps

Next choosing-> OAuth for Apps: Windows Samples then the github example the-> OAuthDesktopApp example.

Using this code with a slight modification to work within Unity allows you to return an AccessToken from Google to work within the Unity environment C# as a "Google Sign-In for Desktop" its perfect, you could have it as an extra tab along side the "Setting up PlayFab authentication using Google and HTML5" but instead it could be

"Setting up PlayFab authentication using Google and Unity" from the countless threads I've read through looking for a solution users definitely need this.

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.

JayZuo avatar image JayZuo ♦ commented ·

Currently, AccessToken is not recommended to use, but PlayFab will still support it. It won't be removed unless Google does not support it any more.

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.