示例#1
0
 public void DidComplete(ASAuthorizationController controller, ASAuthorization authorization)
 {
     // Determine whether the user authenticated via Apple ID or a stored iCloud password.
     if (authorization.GetCredential <ASAuthorizationAppleIdCredential>() is { } appleIdCredential)
     {
         CompletedWithAppleId?.Invoke(controller, appleIdCredential);
     }
示例#2
0
        public void DidComplete(ASAuthorizationController _, ASAuthorization auth)
        {
            var cred = auth.GetCredential <ASAuthorizationAppleIdCredential>();

            var userIdentifier = cred.User;
            var fullName       = cred.FullName;
            var email          = cred.Email;
            var identityToken  = cred.IdentityToken;
            var authCode       = cred.AuthorizationCode;

            // send details to the server

            View.FillWith(new UITextView
            {
                Text =
                    $"\r\n\r\nUser Identifier\r\n {userIdentifier}\r\n\r\n" +
                    $"Full Name\r\n{fullName.GivenName} {fullName.FamilyName}\r\n\r\n" +
                    $"Email\r\n{email}\r\n\r\n" +
                    $"IdentityToken\r\n{identityToken.ToString().Substring(0, 200)}\r\n\r\n" +
                    $"AuthCode\r\n{authCode.ToString().Substring(0, 40)}",

                TextAlignment = UITextAlignment.Center,
                Font          = UIFont.GetMonospacedSystemFont(16, UIFontWeight.Regular),
            }, 40, 50);
        }
        public void DidComplete(ASAuthorizationController controller, ASAuthorization authorization)
        {
            var credential = authorization.GetCredential <ASAuthorizationAppleIdCredential>();

            if (credential != null && !string.IsNullOrEmpty(currentNonce))
            {
                appleToken = credential.IdentityToken.ToString();
                var firebaseCredential = OAuthProvider.GetCredentialWithRawNonce("apple.com", credential.IdentityToken.ToString(), currentNonce);
                Auth.DefaultInstance.SignInWithCredential(firebaseCredential, SignInOnCompletion);
            }
            else
            {
                appleToken = string.Empty;
                SetVerificationStatus(VerificationStatus.Failed, "Sign in failed");
            }
        }
示例#4
0
        public void DidComplete(ASAuthorizationController controller, ASAuthorization authorization)
        {
            if (authorization.GetCredential <ASAuthorizationAppleIdCredential> () is ASAuthorizationAppleIdCredential appleIdCredential)
            {
                var userIdentifier = appleIdCredential.User;
                var fullName       = appleIdCredential.FullName;
                var email          = appleIdCredential.Email;

                // Create an account in your system.
                // For the purpose of this demo app, store the userIdentifier in the keychain.
                try {
                    new KeychainItem("com.xamarin.AddingTheSignInWithAppleFlowToYourApp", "userIdentifier").SaveItem(userIdentifier);
                } catch (Exception) {
                    Console.WriteLine("Unable to save userIdentifier to keychain.");
                }

                // For the purpose of this demo app, show the Apple ID credential information in the ResultViewController.
                if (!(PresentingViewController is ResultViewController viewController))
                {
                    return;
                }

                InvokeOnMainThread(() => {
                    viewController.UserIdentifierText = userIdentifier;
                    viewController.GivenNameText      = fullName?.GivenName ?? "";
                    viewController.FamilyNameText     = fullName?.FamilyName ?? "";
                    viewController.EmailText          = email ?? "";

                    DismissViewController(true, null);
                });
            }
            else if (authorization.GetCredential <ASPasswordCredential> () is ASPasswordCredential passwordCredential)
            {
                // Sign in using an existing iCloud Keychain credential.
                var username = passwordCredential.User;
                var password = passwordCredential.Password;

                // For the purpose of this demo app, show the password credential as an alert.
                InvokeOnMainThread(() => {
                    var message         = $"The app has received your selected credential from the keychain. \n\n Username: {username}\n Password: {password}";
                    var alertController = UIAlertController.Create("Keychain Credential Received", message, UIAlertControllerStyle.Alert);
                    alertController.AddAction(UIAlertAction.Create("Dismiss", UIAlertActionStyle.Cancel, null));

                    PresentViewController(alertController, true, null);
                });
            }
        }
示例#5
0
        public void DidComplete(ASAuthorizationController controller, ASAuthorization authorization)
        {
            var creds = authorization.GetCredential <ASAuthorizationAppleIdCredential>();

            tcsCredential?.TrySetResult(creds);
        }
 public override void DidComplete(ASAuthorizationController controller, ASAuthorization authorization)
 {
     _tcs.TrySetResult(authorization.GetCredential <ASAuthorizationAppleIdCredential>());
 }