question

fknauer avatar image
fknauer asked

Authenticate with GooglePlay Services: Login works, Link does not

Setup:

Unity 5.6.1.p4

play-games-plugin-for-unity: v0.9.39a

PlayFabSdk: 2.23.170612

I am able to authenticate with GooglePlay Services and can obtain a ServerAuthCode.

My fist login flow is like this:

I try to login with LoginWithGoogleAccountRequest but dont create an account with it. If the user does not have an accout assigned with GooglePlay I create a account with LoginWithCustomID and save it locally.

When the LoginWithCustomID is successful i try to link the GooglePlay account of the user with LinkGoogleAccount but the link request always returns with "InvalidGoogleToken".

I thought i got something messed up with the ServerAuthCode but then i try to with create account with LoginWithGoogleAccountRequest the ServerAuthCode is valid and the request successful.

I want to keep the CustomId as a default to not be dependent on the availability of google play and use it as a local fallback.

Any idea what could cause the InvalidGoogleToken with LinkGoogleAccount?

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.

1 Answer

·
brendan avatar image
brendan answered

I take it you're attempting to re-use the Server Auth Code you used in the call to LoginWithGoogleAccount in your flow? The problem is that when you called login, we used that code to get a token from Google. Attempting to re-query for a token using the same code is likely resulting in an error. Could you try getting a fresh auth code, and trying to link with it? Under the covers, just so you know, it's literally the same function call on our side to validate the code and get a token, whether it's for a login or a link operation.

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

fknauer avatar image fknauer commented ·

Thanks for the quick answer. Yes I am using the same Server Auth Code for both calls. I was not aware that the code gets invalid after using it once. The official play games plugin from google is caching the Server Auth Code for the whole session so I have to re authenticate the user to get a fresh code.

0 Likes 0 ·
brendan avatar image brendan fknauer commented ·

It's not that it's invalidated, but an attempt to get a token from it will return an error after the first try - it can still be used for a refresh token, but that would be for after the first sign-in.

0 Likes 0 ·
fknauer avatar image fknauer commented ·

Are you sure that this is the intended behavior? I want to be able that the user can switch between different PlayFab accounts with different google accounts. So when i try to link the google account after the user connected to google play and the account is already claimed i ask the user if he wants to login with the other account. currently i would have to reconnect google play because i "used" the current ServerAuthCode already. Theoretically it should be possible to use the ServerAuthCode several times until its revoked.

0 Likes 0 ·
brendan avatar image brendan fknauer commented ·

I can't really speak to Google's intent, but simply put, when you get the InvalidGoogleToken response, that's specifically because we tried to use the ServerAuthCode to get a Token, and Google returned either invalid_token, invalid_client, or invalid_grant. In the case of re-using a ServerAuthCode, the indication is that they return invalid_grant.

0 Likes 0 ·
fknauer avatar image fknauer commented ·

Thanks for the clarification. My solution is to ask the user to re authenticate if the token is invalid. This only happens in rare cases when the user switches accounts manually.

0 Likes 0 ·
Ben avatar image Ben fknauer commented ·

hello @fknauer can you tell me how to do a reauthenticate? thanks

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.