The Authentication - Login With Google Account docs and Unity SDK are missing the "AccessToken" variable. I found this while trying to set up "login with Google" as an option for all of our platforms. I was going through the Setting up PlayFab authentication using Google and HTML5 tutorial to see how it is done on a platform besides Android. I couldn't get the "ServerAuthCode" variable in the PlayFabClient SDK and LoginWithGoogleAccountRequest to work even when getting the "server auth code" for offline access from this endpoint: "https://accounts.google.com/o/oauth2/v2/auth". Then I tried getting an access token from this endpoint: "https://www.googleapis.com/oauth2/v4/token". Using the access token from that endpoint I would get a response from PlayFab of "malformed code" or something along those lines. That was when I realized the request in the HTML tutorial had a different vairable called "AccessToken"! When using that variable in the request I can now authenticate successfully on any platform with Google!
Not Working Request in Unity PlayFabClientAPI:
LoginWithGoogleAccountRequest request = new LoginWithGoogleAccountRequest { TitleId = PlayFabSettings.TitleId, ServerAuthCode = authToken, InfoRequestParameters = new GetPlayerCombinedInfoRequestParams { GetPlayerProfile = true } }; PlayFabClientAPI.LoginWithGoogleAccount(request, OnLoginSucceeded, OnLoginFailed);
Workaround:
using (HttpClient client = new HttpClient()) { var jsonBodyContent = new { AccessToken = authToken, CreateAccount = true, TitleId = PlayFabSettings.TitleId }; StringContent bodyContent = new StringContent(JsonConvert.SerializeObject(jsonBodyContent), Encoding.UTF8, "application/json"); var result = await client.PostAsync($"https://{PlayFabSettings.TitleId}.playfabapi.com/Client/LoginWithGoogleAccount", bodyContent); Debug.Log(await result.Content.ReadAsStringAsync()); }
I can now authenticate all of my platforms with Google :).
The act of doing this and following the OAuth 2.0 process wasn't too challenging. I figured all of that out in a few hours. It then took me the next couple of days to figure out why I couldn't authenticate with the PlayFabClientAPI in Unity. The SDK and docs are missing the "AccessToken" variable so the current workaround is to hit the endpoint directly by creating an Http request separate from the SDK.
TL; DR;
The Unity PlayFab SDK and Authentication - Login With Google Account docs are missing the "AccessToken" variable.
Update:
The particular section in the html docs where the "AccessToken" variable is used can be found here.