question

Tarm avatar image
Tarm asked

LoginWithGoogleAccount Error Unauthorized

Using Unity 2019 along with Google's Google Play Games Unity plugin.

I've seen this issue crop up in the questions a couple of times, however none of the answers have fixed this issue for me. I successfully authenticate with Google Play Services and obtain a ServerAuthCode. However, when trying to authenticate with PlayFab using LoginWithGoogleAccount request I receive the error report: "Google API error code: invalid_client details: Unauthorized".

Here's a quick breakdown of steps I've taken:

1. Followed and implemented the instructions at least 3 times: https://docs.microsoft.com/en-us/gaming/playfab/features/authentication/platform-specific-authentication/google-sign-in-unity

2. Created a linked web app on Google Play Console as per the above instructions and then copied the client ID and secret over to my PlayFab title's addons/Google settings.

3. In Unity, ensured that Play Games Platform is initialised correctly, requesting profile auth scope:

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.AddOauthScope("profile")
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);

4. Once authenticated with Google, ensured that the ServerAuthCode is not null or empty (looks to be a valid code):

var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();

5. Used the code from the PlayFab example to authenticate with PlayFab:

PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest(){
                
TitleId = PlayFabSettings.TitleId,
ServerAuthCode = serverAuthCode,
CreateAccount = true}, (result) =>
{
Debug.Log("Signed In as " + result.PlayFabId);

}, OnPlayFabError);

At this stage unfortunately an error is always called:

Error.message = "InvalidGoogleToken"

Error.GenerateErrorReport() = "Google API error code: invalid_client details: Unauthorized"

Any help on this would be greatly appreciated.

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.

Seth Du avatar image Seth Du ♦ commented ·

May I ask do you test login on an Android device? In addition, have you followed the instructions for plugin configuration:https://github.com/playgameservices/play-games-plugin-for-unity

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

Yes, all tests are on Android devices.I have followed Google's instructions for plugin confirmation too.

I'm convinced that the plugin side with web client ID is setup correctly since Google Play login returns success and then calling PlayGamesPlatform.Instance.GetServerAuthCode() returns a long string. Just to sanity check I altered a couple of the characters in the Web App Client ID and made a build. This resulted in the Google login to fail.

0 Likes 0 ·
Tarm avatar image Tarm Tarm commented ·

OK. I've been double checking everything again. I've managed to get it working! A little bit embarassing, since this issue has been discussed in a previous post. When copying google client ID and secret from Google API to PlayFab Google Addon, there was whitespace at the start of the secret.

0 Likes 0 ·

1 Answer

·
Tarm avatar image
Tarm answered

When copying google client ID and secret from Google API to PlayFab Google Addon, there was whitespace at the start of the 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.

Seth Du avatar image Seth Du ♦ commented ·

Thanks for the updates. Please feel free to tell us if you have any other questions.

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.