question

pdaz avatar image
pdaz asked

Google AuthCode is redeemed

Is there a way to use one Google Play Games Auth Code twice?

I faced this problem when tried to implement linking. It takes 2 steps.

1. Try to LoginWithGoogleAccount (CreateAccount = false). If I receive AccountNotFound I go to 2nd step.

2. LoginWithAndroidDeviceID and after that LinkGoogleAccount, UnlinkAndroidDeviceID.

So on 2nd step I use same AuthCode and get error that it is redeemed at 1st step.

It is imposible to get a new code from Google Play Games Plugin.

Account Management
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

Correct - Google's auth code is specifically a one-time-use code. What we would recommend is reversing the order of priority of the logins. Use the device ID for the login first. If that's the wrong account (or no account exists), then you would log in with the auth code and link the device ID to that account. That way, you'll log into that account in the first step the next time you run on that device.

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

pdaz avatar image pdaz commented ·

That is not what I wanted. When I will login with Google and link the device ID it will be a new account. I need to save old player data so I have to link Google to old account, not otherwise.

0 Likes 0 ·
brendan avatar image brendan pdaz commented ·

Unfortunately, we can't force Google to give us a multi-use auth code - their policy is clear.

But let me ask - what, specifically, is your user flow? Why is a new account required in your case? If you're always using Device ID as the primary login mechanism, and linking the Google account to the account you log into with the Device ID, what is the user flow that requires multiple Google logins? Or if you always want to use Google login, why use the Device ID login at all?

0 Likes 0 ·
pdaz avatar image pdaz brendan commented ·

Now I only have device ID login. But device ID is not always unique and there are problems when buying new phone. So I want all old users to use Google prior to device ID. Every old user will login with device ID, link Google and unlink device.

But what if user has 2nd phone? He will login with device ID and try to link to same Google again. What will happen? So first he needs to check if he can login with Google.

0 Likes 0 ·
Show more comments
Show more comments
Justin avatar image Justin commented ·

@Brendan Could this be used for a second auth code in this use case? It is something I just found after encountering a simlar issue with Auth flow. I have not tried it yet since we kind of scrapped our flow after I read this conversation.

https://github.com/playgameservices/play-games-plugin-for-unity/blob/master/README.md

Getting another server auth code after exchanging the first code

If your back end server interactions requires you to send a server auth code more than once per authenticated session, you can call PlaPlayGamesPlatform.Instance.GetAnotherServerAuthCode(Action<string> callback) This method requires the player to be aready authenticated and correctly configured to request server auth codes on this client. This method is implemented by calling Google Sign-in silently which returns a new server auth code when already signed in.

0 Likes 0 ·
brendan avatar image brendan Justin commented ·

Yes, it looks like at some point after the thread above, Google added GetAnotherServerAuthCode, specifically to address this need. Thanks!

1 Like 1 ·
pdaz avatar image pdaz brendan commented ·

For a new game I decided to use GetAnotherServerAuthCode. How my code works:

- try to Login with Google, not creating new account;

- if false I create new account with deviceId and link Google;

What went wrong: when I try to link Google with new AuthCode I get strange error GoogleOAuthNoIdTokenIncludedInResponse

What works: I can login with my first AuthCode if account exists.

0 Likes 0 ·
5.jpg (126.8 KiB)

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.