Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • Bugs /
avatar image
Question by TCROC · Apr 16, 2020 at 10:16 PM · apissdksunity3dAuthenticationdocumentation

"Authentication - Login With Google Account" docs and Unity SDK are missing the "AccessToken" variable

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.

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Sarah Zhang · Apr 17, 2020 at 08:44 AM

Thanks for your sharing. We will inform our team about this issue of documentation content’s omission and try to reproduce this issue of Unity SDK.

Comment
TCROC

People who like this

1 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by TCROC · Apr 29, 2020 at 12:20 AM

Another workaround is to extend the "LoginWithGoogleAccountRequest" and add the missing argument. This is much nicer because then you can still use the SDK:

public class LoginWithGoogleAccountRequestAccessToken : LoginWithGoogleAccountRequest
{
	public string AccessToken;
}


Where "LoginWithGoogleAccountRequest" is the request included in the SDK. Then you can use the SDK like:

var loginRequest = new LoginWithGoogleAccountRequestAccessToken
{
    AccessToken = authToken,
    CreateAccount = true,
    TitleId = PlayFabSettings.TitleId
};


PlayFabClientAPI.LoginWithGoogleAccount(loginRequest, OnLoginSucceeded, OnLoginFailed);

I don't want to mark this answer as correct because it is just a workaround. I will wait until we get an official answer from PlayFab when the SDK is fixed.

Comment
TCROC
David Wu

People who like this

2 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Tung Thanh Nguyen · Dec 18, 2020 at 09:24 PM

@TCROC: Hi, i am new on PlayFab in Unity, can you give me some sample project for google sign-in? Thanks so much, i don't know how to get AccessToken

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    5 People are following this question.

    avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Getting 503 Service Unavailable on CreateGroup using nodejs playfab-sdk from azure cloud function 1 Answer

    Android Build Error 2 Answers

    There is a warning exception in the console when running on android using Unity SDK. 0 Answers

    HttpWebRequest Proxy set to null? 1 Answer

    UE4 Blueprint decodeGetMatchmakerGameInfoResult 3 Answers

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges