using AppleAuth.Enums;
using AppleAuth.Extensions;
using AppleAuth.Interfaces;
using System;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
[Serializable]
public class GameMenuHandler
{
public GameObject Parent;
public Text AppleUserIdLabel;
public Text AppleUserCredentialLabel;
public void SetVisible(bool visible)
{
this.Parent.SetActive(visible);
}
public void SetupAppleData(string appleUserId, ICredential receivedCredential)
{
this.AppleUserIdLabel.text = "Apple User ID: " + appleUserId;
if (receivedCredential == null)
{
this.AppleUserCredentialLabel.text = "NO CREDENTIALS RECEIVED\nProbably credential status for " + appleUserId + "was Authorized";
return;
}
var appleIdCredential = receivedCredential as IAppleIDCredential;
var passwordCredential = receivedCredential as IPasswordCredential;
if (appleIdCredential != null)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("RECEIVED APPLE ID CREDENTIAL.\nYOU CAN LOGIN/CREATE A USER WITH THIS");
stringBuilder.AppendLine("Username: " + appleIdCredential.User);
stringBuilder.AppendLine("Real user status: " + appleIdCredential.RealUserStatus.ToString());
if (appleIdCredential.State != null)
stringBuilder.AppendLine("State: " + appleIdCredential.State);
if (appleIdCredential.IdentityToken != null)
{
var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken, 0, appleIdCredential.IdentityToken.Length);
stringBuilder.AppendLine("Identity token (" + appleIdCredential.IdentityToken.Length + " bytes)");
stringBuilder.AppendLine(identityToken.Substring(0, 45) + "...");
}
if (appleIdCredential.AuthorizationCode != null)
{
var authorizationCode = Encoding.UTF8.GetString(appleIdCredential.AuthorizationCode, 0, appleIdCredential.AuthorizationCode.Length);
stringBuilder.AppendLine("Authorization Code (" + appleIdCredential.AuthorizationCode.Length + " bytes)");
stringBuilder.AppendLine(authorizationCode.Substring(0, 45) + "...");
}
if (appleIdCredential.AuthorizedScopes != null)
stringBuilder.AppendLine("Authorized Scopes: " + string.Join(", ", appleIdCredential.AuthorizedScopes));
if (appleIdCredential.Email != null)
{
stringBuilder.AppendLine();
stringBuilder.AppendLine("EMAIL RECEIVED: YOU WILL ONLY SEE THIS ONCE PER SIGN UP. SEND THIS INFORMATION TO YOUR BACKEND!");
stringBuilder.AppendLine("You can test this again by revoking credentials in Settings");
stringBuilder.AppendLine("Email: " + appleIdCredential.Email);
}
if (appleIdCredential.FullName != null)
{
var fullName = appleIdCredential.FullName;
stringBuilder.AppendLine();
stringBuilder.AppendLine("NAME RECEIVED: YOU WILL ONLY SEE THIS ONCE PER SIGN UP. SEND THIS INFORMATION TO YOUR BACKEND!");
stringBuilder.AppendLine("You can test this again by revoking credentials in Settings");
stringBuilder.AppendLine("Name: " + fullName.ToLocalizedString());
stringBuilder.AppendLine("Name (Short): " + fullName.ToLocalizedString(PersonNameFormatterStyle.Short));
stringBuilder.AppendLine("Name (Medium): " + fullName.ToLocalizedString(PersonNameFormatterStyle.Medium));
stringBuilder.AppendLine("Name (Long): " + fullName.ToLocalizedString(PersonNameFormatterStyle.Long));
stringBuilder.AppendLine("Name (Abbreviated): " + fullName.ToLocalizedString(PersonNameFormatterStyle.Abbreviated));
if (appleIdCredential.FullName.PhoneticRepresentation != null)
{
var phoneticName = appleIdCredential.FullName.PhoneticRepresentation;
stringBuilder.AppendLine("Phonetic name: " + phoneticName.ToLocalizedString());
stringBuilder.AppendLine("Phonetic name (Short): " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Short));
stringBuilder.AppendLine("Phonetic name (Medium): " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Medium));
stringBuilder.AppendLine("Phonetic name (Long): " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Long));
stringBuilder.AppendLine("Phonetic name (Abbreviated): " + phoneticName.ToLocalizedString(PersonNameFormatterStyle.Abbreviated));
}
}
this.AppleUserCredentialLabel.text = stringBuilder.ToString();
}
else if (passwordCredential != null)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("USERNAME/PASSWORD RECEIVED (iCloud?)");
stringBuilder.AppendLine("Username: " + passwordCredential.User);
stringBuilder.AppendLine("Password: " + passwordCredential.Password);
this.AppleUserCredentialLabel.text = stringBuilder.ToString();
}
else
{
this.AppleUserCredentialLabel.text = "Unknown credentials for user " + receivedCredential.User;
}
}
}