2017-05-11

In this post, we will see an example of how to display a SharePoint page in the IOS mobile app using the WebView control using NTLM authentication. For this example, I have used my local SharePoint 2016 environment with a self-signed certificate and the Visual Studio for Mac.

Steps:

  1. Add a WebView control to the ViewController.
  2. Create a ConnectionDelegate to handle the SSL and Authentication. Please include the below section as a code sample:
    public class ConnectionDelegate : NSUrlConnectionDelegate
    {
        private readonly UIWebView _webView;
        private NSUrlRequest _request;
     
        public ConnectionDelegate(UIWebView parent, NSUrlRequest request)
        {
            _webView = parent;
            _request = request;
        }
     
        public override void WillSendRequestForAuthenticationChallenge(NSUrlConnection connection,
                     NSUrlAuthenticationChallenge challenge)
        {
                     
            if (challenge.ProtectionSpace.AuthenticationMethod == NSUrlProtectionSpace.AuthenticationMethodNTLM)
            {
     
             var credential = new NSUrlCredential("domain\\userid", "password", NSUrlCredentialPersistence.ForSession);
                         challenge.Sender.UseCredential(credential, challenge);
                         challenge.Sender.ContinueWithoutCredential(challenge);
     
                     }
            else if (challenge.ProtectionSpace.AuthenticationMethod == NSUrlProtectionSpace.AuthenticationMethodServerTrust)
            {
               challenge.Sender.UseCredential(NSUrlCredential.FromTrust(challenge.ProtectionSpace.ServerSecTrust), challenge);
                         challenge.Sender.ContinueWithoutCredential(challenge);
            }
     
            return;
         }
     
     }
  3. Attach the custom delegate class to the WebView to handle the authentication.
    var urlComponents = new NSUrlComponents("https://portal.contoso.com");
    WebView.ShouldStartLoad = (webView, request, navType) =>
                 {
     
                     var urlConnection = NSUrlConnection.FromRequest(request, new ConnectionDelegate(webView, request));
                     urlConnection.Start();
     
                     return true;
                 };
                 
    WebView.LoadRequest(new NSUrlRequest(urlComponents.Url));
  4. Run the application to display the SharePoint page within the webview.

 

(Visited 197 times, 1 visits today)

About the author 

Balamurugan Kailasam

Download 6 Free Ebooks (No email needed)

There are Beginner Ebooks on Power BI, Power Automate and Teams. 2 Microsoft Teams Governance Ebooks and a very popular Power Users Guide to SharePoint!