question

brandon avatar image
brandon asked

LoginWithGoogleAccount,LoginWithGoogleAccount tokenID versus serverAuthCode

I am trying to offer my users a "Login With Google" button as an alternative to Facebook. The feature will be supported on both iOS and Android and I want the user to explicitly log into a Google account and not some implicit Google Play Game Services ID (I've already got GPGS covered). I'm confused on how PlayFab authenticates using Google tokens.

I'm using the Google-SignIn-Unity plugin to authenticate the users with Google. The plugin returns both server auth codes (serverAuthCode) and tokens (tokenId) depending on whether the user is already authenticated or not. Now to my understanding the server auth code is a one time code that is exchanged to get a token that is expected to be used until it expires.

When I try to use LoginWithGoogleAccount or LinkGoogleAccount I can pass in the server auth code as the "ServerAuthCode" parameter and everything works as expected. The problem is when the user reopens the app. The user is already authenticated with Google so the plugin I'm using only gives me the token (as I expect it to), but regardless if I pass that token as "ServerAuthCode" or "AccessToken" in either LoginWithGoogleAccount or LinkGoogleAccount it fails. I've tried requesting another server auth code but the plugin refuses to give me one as long as the user is authenticated, which sounds like the correct result to me as I understand the paradigm.

How have other people dealt with this in their games? Am I misunderstanding something between server auth codes and tokens? Or should I be using a plugin that can give me a server auth code whenever I need it, and if so which one (for Unity mobile)?

,

I'm am currently trying to offer a "Login with Google" button as a source of authentication for my users as an alternative to Facebook. Please note that I am doing this on both iOS and Android and I expect the user to explicitly log into a Google account and not use GPGS. I am confused on how PlayFab authenticates users with Google tokens.

The plugin I'm using (Google-SignIn-Unity) returns both server auth codes (serverAuthCode) as well as tokens (tokenId). Now as I understand it the purpose of the server auth code is to be a one time use that is exchanged for a token that is valid for a certain amount of time (usually months). The plugin returns the serverAuthCode the first time, then the tokenId on subsequent calls as you would expect based on the paradigm.

When I use LoginWithGoogleAccount or LinkGoogleAccount I can pass in the serverAuthCode as the "ServerAuthCode" parameter and everything works fine. My confusion is what do I do every other time? The next time the user opens the app they are still authenticated with Google. I have a token that I presumably am supposed to use until it expires and as I stated earlier the serverAuthCode is single use. I've tried passing in the token that the plugin gives me as both "ServerAuthCode" and "AccessToken" but neither work. I would request another server auth code but for some reason the plugin insists on only giving me a token (which makes sense to me because the user is already authenticated).

I was wondering what other people do to overcome this problem? Is there something I'm missing or understand incorrectly about tokens and auth codes?

sdksAuthentication
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

It's the latter - you need to pass us a fresh ServerAuthCode each time you call LoginWithGoogleAccount or LInkGoogleAccount. If your plugin is blocking that, you'll need to switch to one that doesn't. In terms of plugins to use, quite a few of the developers we work with use the Google Play plugin directly: https://github.com/playgameservices/play-games-plugin-for-unity.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.