How to identify a mobile User in Unity without an explicit registration

Viewed 3376

First of all, I have been searching forums for about a year for a viable solution. What I am looking for is a way to identify a mobile User by an ID that is NOT linked to the device.

So no SystemInfo.deviceUniqueIdentifier

My thoughts go out towards identifying Users using the Google Account of the User (Android) or the Apple account (iOS).

What I have tried so far is connecting the application through the GooglePlayGames API. It is successfully connected and works fine. It logs in automatically when I start the application and I retrieve and store the googleId in my database. The drawback here however is that the app is now dependent on GooglePlayGames, which is something I dislike. I don't like explicit dependencies on other apps. And I also need to find a suitable equivalent for iOS.

I have yet to implement the Unity IAP to enable in app purchasing. I could not find any info on how transactions are linked to Users on android/ iOS. Is there a way to retrieve/store any User related Id during transactions?

It seems to me that when working with in app purchasing, that you need to have some way to reimburse/reactivate purchases made by users when they switch phones for example.

Best case scenario would be an easy way to store an Id without depending on Unity IAP, so that Free To Play Users can also easily recover their account.

2 Answers

You can use Mac Address. This is unique for every device.

string GetMacAddress()
{
    string reesult = "";
    foreach (NetworkInterface ninf in NetworkInterface.GetAllNetworkInterfaces())
    {
        if (ninf.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue;
        if (ninf.OperationalStatus == OperationalStatus.Up)
        {
            reesult += ninf.GetPhysicalAddress().ToString();
            break;
        }
    }
    return reesult;
}

Now, if the device is jail-broken or tampered with, the Mac Address can be spoofed or temporary changed.

SystemInfo.deviceUniqueIdentifier is not 100% reliable, especially not on IOS. Furthermore I will lose the connection to the User if he switches device.

You can use Unity's SocialPlatforms API to check if the user is logged in then obtain the user id. That you can use to determine the user on any device.

Social.localUser.Authenticate(success =>
{
    if (success)
    {
        Debug.Log("Authentication successful");

        string userInfo = Social.localUser.id;

        Debug.Log(userInfo);
    }
    else
        Debug.Log("Authentication failed");
});

If you really need more control over your users, you should implement your own token-based authentication such as oauth2. It's not really hard to make one yourself if you have background of PHP and MySQL.

For iOS you need to implement the Apple Game Center.

The docs make it look pretty easy, looks like a single function call that will prompt the user to sign in if they're not already signed in.

Should work the same as the Google Play Store API after that.

Related