Play-games-plugin-for-unity: Authentication always failed

Created on 2 Oct 2017  Â·  8Comments  Â·  Source: playgameservices/play-games-plugin-for-unity

Goog afternoon!

I configure my game as described. The game is in alpha testing (testers accounts are set up). But Social.localUser.Authenticate always return false with "Authentication failed" error. I create and configure an empty project - the same thing.

    IEnumerator Start () {

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()

.RequestEmail()
.RequestServerAuthCode(false)
.RequestIdToken()
.AddOauthScope("profile")
.AddOauthScope("email")
.Build();

        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();


        yield return new WaitForSeconds(5.0f);

        Social.localUser.Authenticate((bool success, string error) =>
        {
            if(success)
            {
                mText.text = ((PlayGamesLocalUser)Social.localUser).GetIdToken();

            }
            else
            {
                mText.text = error;
            }
        });
    }



Tell me, please, what could be the problem.
unity version: 5.6.3f1
plugin version: 0.9.41
The log file:
log.txt

Most helpful comment

Good afternoon! First make sure that you have a service for your application. "Web app" should be in "Linked apps". Exactly "Web app" (together with "Android app"). Create it, if it is not so. The Developer Console should have a key for the "Web application". Add it, if it is not. "Unity/Window/Google play games/Setup/Android setup" must have the client ID from developer console for "Web application" (or "OAuth2 Client ID" from google play console for "Web app", this keys must be same).

void OnLobbyLoaded()
{
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        .RequestIdToken()
        .Build();

    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();
}

// Then OnLobbyConnect is called 

public void OnLobbyConnect()
{
    if(PlayGamesPlatform.Instance.IsAuthenticated())
    {
        StartCoroutine(OnAuthenticate());
    }
    else
    {
        Social.localUser.Authenticate((bool success) =>
        {
            if(success)
            {
                StartCoroutine(OnAuthenticate());
            }
            else
            {
                // GetUserInfo("");
            }
        });
    }
}

IEnumerator OnAuthenticate() {

        // Just in case, I do wait for the token

    string _token = null;
    int counter = 0;
    do
    {
        if(counter++ > 3)
        {
            break;
        }

        yield return new WaitForSeconds(2.0f);

        _token = ((PlayGamesLocalUser)Social.localUser).GetIdToken();
    }  while(string.IsNullOrEmpty(_token));

    if(string.IsNullOrEmpty(_token))
    {
        // GetUserInfo("");

        yield break;
    }

    // GetUserInfo(_token);
}

All 8 comments

I tried PlayGamesPlatform.Activate without initialization and аuthentication is successful.
But with
.RequestIdToken()
((PlayGamesLocalUser)Social.localUser).GetIdToken() is empty

I still can not get IdToken or ServerAuthCode. With following configuration google play serices error occurs.

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.AddOauthScope("email")
.AddOauthScope("profile")
.RequestServerAuthCode(false)
.RequestIdToken()
.Build();

hello.

If you have "Authentication failed" in alpha testing, try adding the Test account to [Game Service] or
check the publishing options.

Google Play Console -> [Game Service] -> Your App -> Testing

If "Authentication Success", IdToken is null, check the WebClient ID.

my plugin version: 0.9.40 but I use idtoken well.

Sorry to depend on Google Translate . (´・ω・`)

I had another problem. I missed the need to create WEB service for application, even if it is not WEB.

my app is crashing using the plugin
How were you able to authenticate without crashing?

hi Femidko:
i meet this problem too, i can authenticate success without calling InitializeInstance method, but get the idtoken result is null, and if i call the InitializeInstance method ,i just authenticate always failure, did you solved this problem? can you share me?

Good afternoon! First make sure that you have a service for your application. "Web app" should be in "Linked apps". Exactly "Web app" (together with "Android app"). Create it, if it is not so. The Developer Console should have a key for the "Web application". Add it, if it is not. "Unity/Window/Google play games/Setup/Android setup" must have the client ID from developer console for "Web application" (or "OAuth2 Client ID" from google play console for "Web app", this keys must be same).

void OnLobbyLoaded()
{
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        .RequestIdToken()
        .Build();

    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();
}

// Then OnLobbyConnect is called 

public void OnLobbyConnect()
{
    if(PlayGamesPlatform.Instance.IsAuthenticated())
    {
        StartCoroutine(OnAuthenticate());
    }
    else
    {
        Social.localUser.Authenticate((bool success) =>
        {
            if(success)
            {
                StartCoroutine(OnAuthenticate());
            }
            else
            {
                // GetUserInfo("");
            }
        });
    }
}

IEnumerator OnAuthenticate() {

        // Just in case, I do wait for the token

    string _token = null;
    int counter = 0;
    do
    {
        if(counter++ > 3)
        {
            break;
        }

        yield return new WaitForSeconds(2.0f);

        _token = ((PlayGamesLocalUser)Social.localUser).GetIdToken();
    }  while(string.IsNullOrEmpty(_token));

    if(string.IsNullOrEmpty(_token))
    {
        // GetUserInfo("");

        yield break;
    }

    // GetUserInfo(_token);
}

Yo guys, make sure that you have installed google play services in android studio SDK Manager. After I did it, rebuild unity project — all works fine.
Screenshot 2020-07-26 at 11 50 06

Was this page helpful?
0 / 5 - 0 ratings

Related issues

temresen picture temresen  Â·  4Comments

brentbartlett picture brentbartlett  Â·  5Comments

parkJeongOck picture parkJeongOck  Â·  4Comments

bibbis picture bibbis  Â·  4Comments

toxikman picture toxikman  Â·  4Comments