public void Authenticate(Uri authorizationUri, Uri redirectUri, RequestContext requestContext)
        {
            try
            {
                if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
                {
                    asWebAuthenticationSession = new AuthenticationServices.ASWebAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri),
                                                                                                       redirectUri.Scheme, (callbackUrl, error) =>
                    {
                        if (error != null)
                        {
                            ProcessCompletionHandlerError(error);
                        }
                        else
                        {
                            ContinueAuthentication(callbackUrl.ToString());
                        }
                    });

                    asWebAuthenticationSession.Start();
                }

                else if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    sfAuthenticationSession = new SFAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri),
                                                                          redirectUri.Scheme, (callbackUrl, error) =>
                    {
                        if (error != null)
                        {
                            ProcessCompletionHandlerError(error);
                        }
                        else
                        {
                            ContinueAuthentication(callbackUrl.ToString());
                        }
                    });

                    sfAuthenticationSession.Start();
                }

                else
                {
                    safariViewController          = new SFSafariViewController(new NSUrl(authorizationUri.AbsoluteUri), false);
                    safariViewController.Delegate = this;
                    viewController.InvokeOnMainThread(() =>
                    {
                        viewController.PresentViewController(safariViewController, false, null);
                    });
                }
            }
            catch (Exception ex)
            {
                requestContext.Logger.ErrorPii(ex);
                throw MsalExceptionFactory.GetClientException(
                          CoreErrorCodes.AuthenticationUiFailedError,
                          "Failed to invoke SFSafariViewController",
                          ex);
            }
        }
        public void Authenticate(Uri authorizationUri, Uri redirectUri, RequestContext requestContext)
        {
            try
            {
                if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
                {
                    asWebAuthenticationSession = new AuthenticationServices.ASWebAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri),
                                                                                                       redirectUri.Scheme, (callbackUrl, error) =>
                    {
                        if (error != null)
                        {
                            ProcessCompletionHandlerError(error);
                        }
                        else
                        {
                            ContinueAuthentication(callbackUrl.ToString());
                        }
                    });

                    asWebAuthenticationSession.BeginInvokeOnMainThread(() =>
                    {
                        if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
                        {
                            // If the presentationContext is missing from the session,
                            // MSAL.NET will pick up an "authentication cancelled" error
                            // With the addition of the presentationContext, .Start() must
                            // be called on the main UI thread
                            asWebAuthenticationSession.PresentationContextProvider =
                                new ASWebAuthenticationPresentationContextProviderWindow();
                        }
                        asWebAuthenticationSession.Start();
                    });
                }

                else if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    sfAuthenticationSession = new SFAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri),
                                                                          redirectUri.Scheme, (callbackUrl, error) =>
                    {
                        if (error != null)
                        {
                            ProcessCompletionHandlerError(error);
                        }
                        else
                        {
                            ContinueAuthentication(callbackUrl.ToString());
                        }
                    });

                    sfAuthenticationSession.Start();
                }
                else
                {
                    safariViewController = new SFSafariViewController(new NSUrl(authorizationUri.AbsoluteUri), false)
                    {
                        Delegate = this
                    };
                    viewController.InvokeOnMainThread(() =>
                    {
                        viewController.PresentViewController(safariViewController, false, null);
                    });
                }
            }
            catch (Exception ex)
            {
                requestContext.Logger.ErrorPii(ex);
                throw new MsalClientException(
                          MsalError.AuthenticationUiFailedError,
                          ex.Message,
                          ex);
            }
        }
        public void Authenticate(Uri authorizationUri, Uri redirectUri, RequestContext requestContext)
        {
            try
            {
                /* For app center builds, this will need to build on a hosted mac agent. The mac agent does not have the latest SDK's required to build 'ASWebAuthenticationSession'
                 * Until the agents are updated, appcenter build will need to ignore the use of 'ASWebAuthenticationSession' for iOS 12.*/
#if !IS_APPCENTER_BUILD
                if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
                {
                    asWebAuthenticationSession = new AuthenticationServices.ASWebAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri),
                                                                                                       redirectUri.Scheme, (callbackUrl, error) =>
                    {
                        if (error != null)
                        {
                            ProcessCompletionHandlerError(error);
                        }
                        else
                        {
                            ContinueAuthentication(callbackUrl.ToString());
                        }
                    });

                    asWebAuthenticationSession.Start();
                }

                else if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    sfAuthenticationSession = new SFAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri),
                                                                          redirectUri.Scheme, (callbackUrl, error) =>
                    {
                        if (error != null)
                        {
                            ProcessCompletionHandlerError(error);
                        }
                        else
                        {
                            ContinueAuthentication(callbackUrl.ToString());
                        }
                    });

                    sfAuthenticationSession.Start();
                }
#else
                if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    sfAuthenticationSession = new SFAuthenticationSession(new NSUrl(authorizationUri.AbsoluteUri),
                                                                          redirectUri.Scheme, (callbackUrl, error) =>
                    {
                        if (error != null)
                        {
                            ProcessCompletionHandlerError(error);
                        }
                        else
                        {
                            ContinueAuthentication(callbackUrl.ToString());
                        }
                    });

                    sfAuthenticationSession.Start();
                }
#endif
                else
                {
                    safariViewController = new SFSafariViewController(new NSUrl(authorizationUri.AbsoluteUri), false)
                    {
                        Delegate = this
                    };
                    viewController.InvokeOnMainThread(() =>
                    {
                        viewController.PresentViewController(safariViewController, false, null);
                    });
                }
            }
            catch (Exception ex)
            {
                requestContext.Logger.ErrorPii(ex);
                throw new MsalClientException(
                          MsalError.AuthenticationUiFailedError,
                          "Failed to invoke SFSafariViewController",
                          ex);
            }
        }