Thaina / google-signin-unity

Google Sign-In API plugin for Unity game engine. Works with Android and iOS.
Other
23 stars 8 forks source link

[Help needed] clientID for Play Games log in #8

Open lichengz opened 1 month ago

lichengz commented 1 month ago

Hi,

Could anyone help me find out where to enter a clientID for Play Games log in?

Thanks.

Thaina commented 1 month ago

For android, I don't think you need client ID. It seem google will use bundle ID of the app and figure out by itself For ios though, it seem you need to update your Info.plist in xcode project If you want serverAuthCode or IdToken, there is webClientId in configuration. And you need to create and use credential Id for web page

lichengz commented 1 month ago

For android, I don't think you need client ID. It seem google will use bundle ID of the app and figure out by itself For ios though, it seem you need to update your Info.plist in xcode project If you want serverAuthCode or IdToken, there is webClientId in configuration. And you need to create and use credential Id for web page

Hi, thank you for you quick response! I'm making an android build. I was using Google Play Games plugin for Unity, which asks me to provide client ID and it works. Now I switched to your port of Google log in plugin, which is for sure amazing. However, I got a No Client ID found error when calling OnGamesSignIn, and I don't remeber I ever provided a client ID.

Thaina commented 1 month ago

Thank for reporting. I will take a look

lichengz commented 1 month ago

sounds good, thanks!

the original google-signin-unity documention didn't mention anything about providing a clientID for Play Games. however, according to https://github.com/playgameservices/play-games-plugin-for-unity, a clientID is required. so confusing...

lichengz commented 1 month ago

2024/06/12 11:45:44.723 13246 13273 Error Unity AndroidJavaException: java.lang.IllegalArgumentException: serverClientId should not be empty 2024/06/12 11:45:44.723 13246 13273 Error Unity java.lang.IllegalArgumentException: serverClientId should not be empty 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.google.android.libraries.identity.googleid.GetGoogleIdOption.(com.google.android.libraries.identity.googleid:googleid@@1.1.0:4) 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.google.android.libraries.identity.googleid.GetGoogleIdOption$Builder.build(com.google.android.libraries.identity.googleid:googleid@@1.1.0:1) 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.google.googlesignin.GoogleSignInHelper$1.apply(GoogleSignInHelper.java:164) 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.google.googlesignin.GoogleSignInHelper$1.apply(GoogleSignInHelper.java:140) 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.google.googlesignin.GoogleSignInHelper.signIn(GoogleSignInHelper.java:237) 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.unity3d.player.UnityPlayer.-$$Nest$mnativeRender(Unknown Source:0) 2024/06/12 11:45:44.723 13246 13273 Error Unity at com.unity3d.player.UnityPlayer$F$a.handleMessage(Unknown Source:122) 2024/06/12 11:45:44.723 13246 13273 Error Unity at android.os.Handler.dispatchMessage(Handler.java:102) 2024/06/12 11:45:44.723 13246 13273 Error Unity at android.os.Looper.loopOnce(Looper.java:230)

Thaina commented 1 month ago

Based on your log, it seem there might be a bug of mine, or q change in behaviour

But it might be success if you have pass webClientId (making a web credential) and set it at GoogleSignInConfiguration.WebClientId

Based on the old document, we still need Google Sign-In configuration file in the project and also my new package might failed to read that, I am currently investigating

Thaina commented 1 month ago

As far as I can see, currently now it seem google insist that you need to have both credential for android and web. And you need clientId of web credential to set in the configuration

https://developer.android.com/identity/sign-in/credential-manager-siwg#set-google

lichengz commented 1 month ago

Hi I can confirm that my project have both andoird and web client IDs. It works with Google Play Games plugin for Unity So I think now the problem is how to tell google-signin-unity what the android client ID is. image

Thaina commented 1 month ago

My project don't have anything declare android client ID at all and it work fine just providing web client ID

Thaina commented 1 month ago

This is only file exist in my sample project, not even google configuration file needed

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Google;
using System.Threading.Tasks;

public class GoogleSignInBehaviour : MonoBehaviour
{
    [RuntimeInitializeOnLoadMethod]
    static void Config()
    {
        GoogleSignIn.Configuration = new GoogleSignInConfiguration() {
            RequestEmail = true,
            RequestProfile = true,
            RequestIdToken = true,
            RequestAuthCode = true,
            WebClientId = "XXXXXXXXX-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
#if UNITY_EDITOR || UNITY_STANDALONE
            ClientSecret = "XXXXXX-xxxXXXxxxXXXxxx-xxxxXXXXX"
#endif
        };
    }

    [SerializeField]
    TMPro.TMP_Text text;

    public void SignIn()
    {
        GoogleSignIn.DefaultInstance.SignIn().ContinueWith((task) => {
            var user = task.Result;
            text.text = string.Join("\n",new [] {
                user.UserId,
                user.Email,
                user.DisplayName,
                user.ImageUrl.AbsoluteUri,
                user.IdToken,
                user.AuthCode,
            });
        },TaskScheduler.FromCurrentSynchronizationContext());
    }
}
konstantin890 commented 1 day ago

@Thaina Do you have anything set for "Authorized JavaScript Origins" and "Authorized redirect URIs" for the Web App Client ID in the Cloud Dashboard? Because I'm trying to run the script above with just WebClientId but I get this error when I select an account from the popup:

2024/07/16 00:27:44.120 23713 23713 Error Unity onFailure class androidx.credentials.exceptions.GetCredentialCancellationException : [16] Account reauth failed.

Thaina commented 22 hours ago

I have set localhost and firebase for Authorized js relate setting. Maybe localhost was needed, but I don't think so

Do you have both android and webclientID ? I think it need both

konstantin890 commented 4 hours ago

I have resolved the issue - it seems like an Android Client ID has to exist within the same project in the Cloud Dashboard (even though you only use the Web App Client ID). Adding localhost in Authorized redirects URI made it work for the Editor.

Thanks a lot!