Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GLeBaTi · Apr 21, 2016 at 12:59 PM · iphoneappleauthenticationgamecenter

Apple iphone authentification

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)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by GLeBaTi · Apr 26, 2016 at 06:01 AM

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);
         }
     }



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

45 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I use Apple's SFSymbols in my app? 1 Answer

Prepare Different Resolutions App Preview Videos for Apple Store 0 Answers

GameCenter Not Connecting 1 Answer

IMEI Checker App 0 Answers

Subscription Purchase in iOS 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges