Skip to content

Instantly share code, notes, and snippets.

@bhupiister
Last active March 23, 2022 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhupiister/c329c33ae6a217f34193728d93a3e7d9 to your computer and use it in GitHub Desktop.
Save bhupiister/c329c33ae6a217f34193728d93a3e7d9 to your computer and use it in GitHub Desktop.
Unity Google Sign in plugin with Firebase, App crashes with error configuration is null!? and Request not configured! Failing authenticate
namespace Google.Impl {
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
internal class GoogleSignInImpl : BaseObject, ISignInImpl {
#if UNITY_ANDROID
private const string DllName = "native-googlesignin";
#else
private const string DllName = "__Internal";
#endif
internal GoogleSignInImpl(GoogleSignInConfiguration configuration)
: base(GoogleSignIn_Create(GetPlayerActivity()))
{
Configure(configuration);
}
public void Configure(GoogleSignInConfiguration configuration)
{
if (configuration != null)
{
List<string> scopes = new List<string>();
if (configuration.AdditionalScopes != null)
{
scopes.AddRange(configuration.AdditionalScopes);
}
GoogleSignIn_Configure(SelfPtr(), configuration.UseGameSignIn,
configuration.WebClientId,
configuration.RequestAuthCode,
configuration.ForceTokenRefresh,
configuration.RequestEmail,
configuration.RequestIdToken,
configuration.HidePopups,
scopes.ToArray(),
scopes.Count,
configuration.AccountName);
}
}
/// <summary>Enables/Disables verbose logging to help troubleshooting</summary>
public void EnableDebugLogging(bool flag) {
GoogleSignIn_EnableDebugLogging(SelfPtr(), flag);
}
/// <summary>
/// Starts the authentication process.
/// </summary>
/// <remarks>
/// The authenication process is started and may display account picker
/// popups and consent prompts based on the state of authentication and
/// the requested elements.
/// </remarks>
public Future<GoogleSignInUser> SignIn() {
IntPtr nativeFuture = GoogleSignIn_SignIn(SelfPtr());
return new Future<GoogleSignInUser>(new NativeFuture(nativeFuture));
}
/// <summary>
/// Starts the authentication process.
/// </summary>
/// <remarks>
/// The authenication process is started and may display account picker
/// popups and consent prompts based on the state of authentication and
/// the requested elements.
/// </remarks>
public Future<GoogleSignInUser> SignInSilently() {
IntPtr nativeFuture = GoogleSignIn_SignInSilently(SelfPtr());
return new Future<GoogleSignInUser>(new NativeFuture(nativeFuture));
}
/// <summary>
/// Signs out the User.
/// </summary>
public void SignOut() {
GoogleSignIn_Signout(SelfPtr());
}
/// <summary>
/// Disconnects the user from the application and revokes all consent.
/// </summary>
public void Disconnect() {
GoogleSignIn_Disconnect(SelfPtr());
}
/// <summary>
/// Creates an instance of the native Google Sign-In implementation.
/// </summary>
/// <remarks>
/// For Android this must be the JNI raw object for the parentActivity.
/// For iOS it is ignored.
/// </remarks>
/// <returns>The pointer to the instance.</returns>
/// <param name="data">Data used in creating the instance.</param>
[DllImport(DllName)]
static extern IntPtr GoogleSignIn_Create(IntPtr data);
[DllImport(DllName)]
static extern void GoogleSignIn_EnableDebugLogging(HandleRef self, bool flag);
[DllImport(DllName)]
static extern bool GoogleSignIn_Configure(HandleRef self,
bool useGameSignIn, string webClientId,
bool requestAuthCode, bool forceTokenRefresh, bool requestEmail,
bool requestIdToken, bool hidePopups, string[] additionalScopes,
int scopeCount, string accountName);
[DllImport(DllName)]
static extern IntPtr GoogleSignIn_SignIn(HandleRef self);
[DllImport(DllName)]
static extern IntPtr GoogleSignIn_SignInSilently(HandleRef self);
[DllImport(DllName)]
static extern void GoogleSignIn_Signout(HandleRef self);
[DllImport(DllName)]
static extern void GoogleSignIn_Disconnect(HandleRef self);
[DllImport(DllName)]
internal static extern void GoogleSignIn_DisposeFuture(HandleRef self);
[DllImport(DllName)]
internal static extern bool GoogleSignIn_Pending(HandleRef self);
[DllImport(DllName)]
internal static extern IntPtr GoogleSignIn_Result(HandleRef self);
[DllImport(DllName)]
internal static extern int GoogleSignIn_Status(HandleRef self);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetServerAuthCode(
HandleRef self, [In, Out] byte[] bytes, UIntPtr len);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetDisplayName(HandleRef self,
[In, Out] byte[] bytes, UIntPtr len);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetEmail(HandleRef self,
[In, Out] byte[] bytes, UIntPtr len);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetFamilyName(HandleRef self,
[In, Out] byte[] bytes, UIntPtr len);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetGivenName(HandleRef self,
[In, Out] byte[] bytes, UIntPtr len);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetIdToken(HandleRef self,
[In, Out] byte[] bytes, UIntPtr len);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetImageUrl(HandleRef self,
[In, Out] byte[] bytes, UIntPtr len);
[DllImport(DllName)]
internal static extern UIntPtr GoogleSignIn_GetUserId(HandleRef self,
[In, Out] byte[] bytes, UIntPtr len);
// Gets the Unity player activity.
// For iOS, this returns Zero.
private static IntPtr GetPlayerActivity() {
#if UNITY_ANDROID && !UNITY_EDITOR
UnityEngine.AndroidJavaClass jc = new UnityEngine.AndroidJavaClass(
"com.unity3d.player.UnityPlayer");
return jc.GetStatic<UnityEngine.AndroidJavaObject>("currentActivity")
.GetRawObject();
#else
return IntPtr.Zero;
#endif
}
}
}
@TechniqueDisciple
Copy link

I have exactly the same problem as you do right now. Following to see if a solution is found

@bhupiister
Copy link
Author

@TechniqueDisciple My problem was solve but i dont have the repo in hand right now. I am sure you will find the solution, if not then let me know will look out in my old computer.

@TechniqueDisciple
Copy link

@bhupiister thanks you for your response. I've been stuck for 2 days on this and still haven't found a solution yet. It would be such a big help if you were able to take a look and perhaps give me a suggestion, would be much appreciated.

@bhupiister
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment