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?
Answer by Brendan · Jun 20, 2017 at 12:22 AM
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.
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.
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.
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.
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.
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.
hello @fknauer can you tell me how to do a reauthenticate? thanks
Do REST API sessions time out? 9 Answers
Link Google Account only partially works 1 Answer
Unlink custom id on password reset 1 Answer