驱蚊app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

109 lines
5.9 KiB

  1. using AppleAuth.Enums;
  2. using AppleAuth.Extensions;
  3. using AppleAuth.Interfaces;
  4. using System;
  5. using System.Text;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. namespace AppleAuthSample
  9. {
  10. [Serializable]
  11. public class GameMenuHandler
  12. {
  13. public GameObject Parent;
  14. public Text AppleUserIdLabel;
  15. public Text AppleUserCredentialLabel;
  16. public void SetVisible(bool visible)
  17. {
  18. this.Parent.SetActive(visible);
  19. }
  20. public void SetupAppleData(string appleUserId, ICredential receivedCredential)
  21. {
  22. this.AppleUserIdLabel.text = "Apple User ID: " + appleUserId;
  23. if (receivedCredential == null)
  24. {
  25. this.AppleUserCredentialLabel.text = "NO CREDENTIALS RECEIVED\nProbably credential status for " + appleUserId + "was Authorized";
  26. return;
  27. }
  28. var appleIdCredential = receivedCredential as IAppleIDCredential;
  29. var passwordCredential = receivedCredential as IPasswordCredential;
  30. if (appleIdCredential != null)
  31. {
  32. var stringBuilder = new StringBuilder();
  33. stringBuilder.AppendLine("RECEIVED APPLE ID CREDENTIAL.\nYOU CAN LOGIN/CREATE A USER WITH THIS");
  34. stringBuilder.AppendLine("<b>Username:</b> " + appleIdCredential.User);
  35. stringBuilder.AppendLine("<b>Real user status:</b> " + appleIdCredential.RealUserStatus.ToString());
  36. if (appleIdCredential.State != null)
  37. stringBuilder.AppendLine("<b>State:</b> " + appleIdCredential.State);
  38. if (appleIdCredential.IdentityToken != null)
  39. {
  40. var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken, 0, appleIdCredential.IdentityToken.Length);
  41. stringBuilder.AppendLine("<b>Identity token (" + appleIdCredential.IdentityToken.Length + " bytes)</b>");
  42. stringBuilder.AppendLine(identityToken.Substring(0, 45) + "...");
  43. }
  44. if (appleIdCredential.AuthorizationCode != null)
  45. {
  46. var authorizationCode = Encoding.UTF8.GetString(appleIdCredential.AuthorizationCode, 0, appleIdCredential.AuthorizationCode.Length);
  47. stringBuilder.AppendLine("<b>Authorization Code (" + appleIdCredential.AuthorizationCode.Length + " bytes)</b>");
  48. stringBuilder.AppendLine(authorizationCode.Substring(0, 45) + "...");
  49. }
  50. if (appleIdCredential.AuthorizedScopes != null)
  51. stringBuilder.AppendLine("<b>Authorized Scopes:</b> " + string.Join(", ", appleIdCredential.AuthorizedScopes));
  52. if (appleIdCredential.Email != null)
  53. {
  54. stringBuilder.AppendLine();
  55. stringBuilder.AppendLine("<b>EMAIL RECEIVED: YOU WILL ONLY SEE THIS ONCE PER SIGN UP. SEND THIS INFORMATION TO YOUR BACKEND!</b>");
  56. stringBuilder.AppendLine("<b>You can test this again by revoking credentials in Settings</b>");
  57. stringBuilder.AppendLine("<b>Email:</b> " + appleIdCredential.Email);
  58. }
  59. if (appleIdCredential.FullName != null)
  60. {
  61. var fullName = appleIdCredential.FullName;
  62. stringBuilder.AppendLine();
  63. stringBuilder.AppendLine("<b>NAME RECEIVED: YOU WILL ONLY SEE THIS ONCE PER SIGN UP. SEND THIS INFORMATION TO YOUR BACKEND!</b>");
  64. stringBuilder.AppendLine("<b>You can test this again by revoking credentials in Settings</b>");
  65. stringBuilder.AppendLine("<b>Name:</b> " + fullName.ToLocalizedString());
  66. stringBuilder.AppendLine("<b>Name (Short):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Short));
  67. stringBuilder.AppendLine("<b>Name (Medium):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Medium));
  68. stringBuilder.AppendLine("<b>Name (Long):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Long));
  69. stringBuilder.AppendLine("<b>Name (Abbreviated):</b> " + fullName.ToLocalizedString(PersonNameFormatterStyle.Abbreviated));
  70. if (appleIdCredential.FullName.PhoneticRepresentation != null)
  71. {
  72. var phoneticName = appleIdCredential.FullName.PhoneticRepresentation;
  73. stringBuilder.AppendLine("<b>Phonetic name:</b> " + phoneticName.ToLocalizedString());
  74. stringBuilder.AppendLine("<b>Phonetic name (Short):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Short));
  75. stringBuilder.AppendLine("<b>Phonetic name (Medium):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Medium));
  76. stringBuilder.AppendLine("<b>Phonetic name (Long):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Long));
  77. stringBuilder.AppendLine("<b>Phonetic name (Abbreviated):</b> " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Abbreviated));
  78. }
  79. }
  80. this.AppleUserCredentialLabel.text = stringBuilder.ToString();
  81. }
  82. else if (passwordCredential != null)
  83. {
  84. var stringBuilder = new StringBuilder();
  85. stringBuilder.AppendLine("USERNAME/PASSWORD RECEIVED (iCloud?)");
  86. stringBuilder.AppendLine("<b>Username:</b> " + passwordCredential.User);
  87. stringBuilder.AppendLine("<b>Password:</b> " + passwordCredential.Password);
  88. this.AppleUserCredentialLabel.text = stringBuilder.ToString();
  89. }
  90. else
  91. {
  92. this.AppleUserCredentialLabel.text = "Unknown credentials for user " + receivedCredential.User;
  93. }
  94. }
  95. }
  96. }