Hi. How can i get user email and token or password from iphone devece?
in android i make this:
Social.localUser.Authenticate // login by google play
GooglePlayGames.PlayGamesPlatform.Instance.GetServerAuthCode //get code for login
((GooglePlayGames.PlayGamesLocalUser)Social.localUser).Email //get email
GooglePlayGames.PlayGamesPlatform.Instance.GetIdToken // get client token
but in iphone i want using google play (becouse not all users have it)
Solution (Unity) + Asset: “iOS SDK Pro - Native API Access”
public class GameCenterAuths
{
public string PlayerId { get; set; }
public string BundleId { get; set; }
public string Name { get; set; }
public string PublicKeyUrl { get; set; }
public string Signature { get; set; }
public string Salt { get; set; }
public ulong Timestamp { get; set; }
public byte[] ConcatSignature()
{
var data = new List<byte>();
data.AddRange(Encoding.UTF8.GetBytes(PlayerId));
data.AddRange(Encoding.UTF8.GetBytes(BundleId));
data.AddRange(CalcHelper.ToBigEndian(Timestamp));
data.AddRange(Convert.FromBase64String(Salt));
return data.ToArray();
}
}
Client:
GameKitXT.LocalPlayerAuthenticated += HandleAppleLocalPlayerAuthenticated;
GameKitXT.LocalPlayerAuthenticationFailed += HandleAppleLocalPlayerAuthenticationFailed;
GameKitXT.AuthenticateLocalPlayer();
private void HandleAppleLocalPlayerAuthenticationFailed(object sender, U3DXT.Core.U3DXTErrorEventArgs e)
{
SharedLib.Log.Logger.Instance.Debug("(social) not authentificated " + e.description);
}
private void HandleAppleLocalPlayerAuthenticated(object sender, EventArgs e)
{
SharedLib.Log.Logger.Instance.Debug("(social) authentificated");
Game.IsAuthenfificatedByAppleService = true;
isAuth = true;
}
/// <summary>
/// Получить временный код подтверждения
/// </summary>
/// <param name="callback">(Android: code, token) (IPhone: signatire, salt)</param>
public static void GetServerAuthCode(Action<GameCenterAuths> callback)
{
if (isAuth)
{
GameKitXT.localPlayer.gkLocalPlayer.GenerateIdentityVerificationSignature((_publicKeyUrl, _signature, _salt, _creationDateSpan, _nserror) =>
{
SharedLib.Log.Logger.Instance.Debug("(social) on verif code");
if (_nserror != null)
SharedLib.Log.Logger.Instance.Debug("(social) error?" + _nserror.ToString());
SharedLib.Log.Logger.Instance.Debug("(social) _publicKeyUrl:" + _publicKeyUrl.ToString());
SharedLib.Log.Logger.Instance.Debug("(social) _signature:" + _signature.ToString());
SharedLib.Log.Logger.Instance.Debug("(social) _salt:" + _salt.ToString());
GameCenterAuths auths = new GameCenterAuths();
auths.BundleId = Application.bundleIdentifier;
auths.Name = GameKitXT.localPlayer.displayName;
auths.PlayerId = GameKitXT.localPlayer.playerID;
auths.PublicKeyUrl = _publicKeyUrl.ToString();
auths.Salt = _salt.ToString();
auths.Signature = _signature.ToString();
auths.Timestamp = _creationDateSpan;
callback(auths);
});
}
}
Server verification:
public class AppleSertificateVerification
{
public static bool ValidateSignature(GameCenterAuths auth)
{
try
{
var cert = GetCertificate(auth.PublicKeyUrl);
if (cert.Verify())
{
var csp = cert.PublicKey.Key as RSACryptoServiceProvider;
if (csp != null)
{
var sha256 = new SHA256Managed();
var sig = auth.ConcatSignature();
var hash = sha256.ComputeHash(sig);
if (csp.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA256"), Convert.FromBase64String(auth.Signature)))
{
// Valid user.
// Do server related user management stuff.
return true;
}
}
}
return false;
}
catch
{
return false;
}
}
private static X509Certificate2 GetCertificate(string url)
{
var client = new WebClient();
var rawData = client.DownloadData(url);
return new X509Certificate2(rawData);
}
}