playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.46k stars 963 forks source link

Cannot Authenticate if RequestServerAuthCode is configured #3124

Closed GabrieleRastelli closed 2 years ago

GabrieleRastelli commented 2 years ago

Hi everyone,

I'm trying to authenticate with GPGS on my mobile unity game in order to get a server auth code to send to my server.

This is the code i'm using:

    void Start()
    {
        ConfigureGPGS();
        SignIntoGPGS(SignInInteractivity.CanPromptOnce, clientConfiguration);
    }

    internal void ConfigureGPGS(){
        clientConfiguration = new PlayGamesClientConfiguration.Builder()
            .RequestServerAuthCode(false)
            .RequestIdToken()
            .Build();
    }

    internal void SignIntoGPGS(SignInInteractivity interactivity, PlayGamesClientConfiguration configuration){
        configuration = clientConfiguration;
        PlayGamesPlatform.InitializeInstance(configuration);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();

        PlayGamesPlatform.Instance.Authenticate(interactivity, (code) =>
        {
            if(code == SignInStatus.Success){
                statusText.text = "OK";
                descriptionText.text = "Server token: " + PlayGamesPlatform.Instance.GetServerAuthCode();
            } else {
                statusText.text = "KO";
                descriptionText.text = "code: " + code;
            }
        });
    }

but i always end in the else statement with "DeveloperError" as code.

I can't find anything helpful in the logs:

GPGSManager:SignIntoGPGS(SignInInteractivity, PlayGamesClientConfiguration)
GPGSManager:Start()

Starting Auth with token client.
GooglePlayGames.Android.AndroidClient:Authenticate(Boolean, Action`1)
GPGSManager:SignIntoGPGS(SignInInteractivity, PlayGamesClientConfiguration)
GPGSManager:Start()

 [Play Games Plugin 0.10.14] 03/09/22 13:55:43 +01:00 DEBUG: Activating PlayGamesPlatform.
System.Action:Invoke()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()

 [Play Games Plugin 0.10.14] 03/09/22 13:55:44 +01:00 DEBUG: PlayGamesPlatform activated: GooglePlayGames.PlayGamesPlatform
System.Action:Invoke()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()

 [Play Games Plugin 0.10.14] 03/09/22 13:55:44 +01:00 DEBUG: Creating platform-specific Play Games client.
System.Action:Invoke()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()

 [Play Games Plugin 0.10.14] 03/09/22 13:55:44 +01:00 DEBUG: Creating Android IPlayGamesClient Client
System.Action:Invoke()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()

Returning an error code.

If I try to authenticate with this configuration:

    internal void ConfigureGPGS(){
        clientConfiguration = new PlayGamesClientConfiguration();
    }

It works fine but i can't get the server auth code.

I already checked my clientId and added the correct email as tester.

What else can I try to do in order to solve my problem?

Thanks

GabrieleRastelli commented 2 years ago

Hi everyone,

I finally managed to get a serverAuthCode with the following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.UI;
using UnityEngine.SocialPlatforms;

public class GPGSManager : MonoBehaviour
{
    private PlayGamesClientConfiguration clientConfiguration;

    void Start()
    {
        ConfigureGPGSForToken();
        SignIntoGPGS(SignInInteractivity.CanPromptOnce, clientConfiguration);
    }

    internal void ConfigureGPGSForToken()
    {
        clientConfiguration = new PlayGamesClientConfiguration.Builder()
            .RequestServerAuthCode(false)
            .Build();
    }

    internal void SignIntoGPGS(SignInInteractivity interactivity, PlayGamesClientConfiguration configuration){
        configuration = clientConfiguration;
        PlayGamesPlatform.InitializeInstance(configuration);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();

        PlayGamesPlatform.Instance.Authenticate(interactivity, (code) =>
        {
            if(code == SignInStatus.Success){
                string token = PlayGamesPlatform.Instance.GetServerAuthCode();
            } else {
                /* whatever */
            }
        });
    }
}

And I also had to change my credential configuration as I was using "Android" instead of "Web application". image

Hope this can be helpful.

Thanks