Sign-in with Apple in Xamarin forms iOS - com.apple.AuthenticationServices.AuthorizationError error 1000.

Pramod Singh 0 Reputation points
2023-08-26T12:25:38.1766667+00:00

I have created a project on Xamarin forms with reference to this link for "Sign in with apple" functionality

https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/signinwithapple/

and while testing it on simulator and as well as on device, I am getting this exception error message while testing Sign in with Apple functionality

"The operation couldn’t be completed (com.apple.AuthenticationServices.AuthorizationError error 1000.)"

below is my sample code -

[assembly: Xamarin.Forms.Dependency(typeof(AppleSignInServiceiOS))]
namespace MyCaseStatus.iOS.Services
{
    public class AppleSignInServiceiOS : IAppleSignInService
    {
//#if __IOS__13
		AuthManager authManager;
//#endif

        bool Is13 => UIDevice.CurrentDevice.CheckSystemVersion(13, 0);
        WebAppleSignInService webSignInService;

        public AppleSignInServiceiOS()
        {
            if (!Is13)
                webSignInService = new WebAppleSignInService();
        }

        public async Task<AppleAccount> SignInAsync()
        {
            // Fallback to web for older iOS versions
            if (!Is13)
                return await webSignInService.SignInAsync();

            AppleAccount appleAccount = default;
			try
			{
				//#if __IOS__13
				var provider = new ASAuthorizationAppleIdProvider();
				var req = provider.CreateRequest();

				authManager = new AuthManager(UIApplication.SharedApplication.KeyWindow);

				req.RequestedScopes = new[] { ASAuthorizationScope.FullName, ASAuthorizationScope.Email };
				var controller = new ASAuthorizationController(new[] { req });

				controller.Delegate = authManager;
				controller.PresentationContextProvider = authManager;

				controller.PerformRequests();

				var creds = await authManager.Credentials;

				if (creds == null)
					return null;

				appleAccount = new AppleAccount();
				//appleAccount.IdToken = JwtToken.Decode(new NSString(creds.IdentityToken, NSStringEncoding.UTF8).ToString());
				appleAccount.Email = creds.Email;
				appleAccount.UserId = creds.User;
				appleAccount.Name = NSPersonNameComponentsFormatter.GetLocalizedString(creds.FullName, NSPersonNameComponentsFormatterStyle.Default, NSPersonNameComponentsFormatterOptions.Phonetic);
				appleAccount.RealUserStatus = creds.RealUserStatus.ToString();
				//#endif
			}
			catch (Exception ex) {
				string Excep = ex.Message;
			}
            return appleAccount;
        }

        public bool Callback(string url) => true;

        //Task<AppleAccount> IAppleSignInService.SignInAsync()
        //{
        //    throw new NotImplementedException();
        //}
    }

//#if __IOS__13
	class AuthManager : NSObject, IASAuthorizationControllerDelegate, IASAuthorizationControllerPresentationContextProviding
	{
		public Task<ASAuthorizationAppleIdCredential> Credentials
			=> tcsCredential?.Task;

		TaskCompletionSource<ASAuthorizationAppleIdCredential> tcsCredential;

		UIWindow presentingAnchor;

		public AuthManager(UIWindow presentingWindow)
		{
			tcsCredential = new TaskCompletionSource<ASAuthorizationAppleIdCredential>();
			presentingAnchor = presentingWindow;
		}

		public UIWindow GetPresentationAnchor(ASAuthorizationController controller)
			=> presentingAnchor;

		[Export("authorizationController:didCompleteWithAuthorization:")]
		public void DidComplete(ASAuthorizationController controller, ASAuthorization authorization)
		{
			var creds = authorization.GetCredential<ASAuthorizationAppleIdCredential>();
			tcsCredential?.TrySetResult(creds);
		}

		[Export("authorizationController:didCompleteWithError:")]
		public void DidComplete(ASAuthorizationController controller, NSError error)
			=> tcsCredential?.TrySetException(new Exception(error.LocalizedDescription));
	}
//#endif
}

I have checked all possible solution for this error but still getting same error every time.

can anyone please help or provide any solution for this error.

I will be very thankful if anyone can provide me a link or reference for solving this error.

Thanks.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,336 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 30,666 Reputation points Microsoft Vendor
    2023-08-28T06:44:39.46+00:00

    Hello,

    error 1000 means that the authorization attempt failed for an unknown reason. And it's usually caused by the code sign /provisioning profile.

    From the sample link you post, you are trying to sign In with Apple in Xamarin.Forms. Please check that you have setup for iOS and selected a correct Provisioning Profile.

    If you have any other issues, please feel free to post in here.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.