I’m developing a custom desktop solution in Windows Presentation Foundation (WPF) that has to access a SharePoint Online contents and do some things with them.

The first thing I had to “fight” with was the Authentication method that is by default a bit different from the On-Premise version (programmatically too). When I started to look for the right documentation about that topic I found quite fast this great article from the MSDN library “Remote Authentication in SharePoint Online Using Claims-Based Authentication” by Robert Bogue. After read the article and download the Sample Code, I told myself “Yeah! This going to be a piece of cake!”.

The first thing I tried was just running the sample against my own server to check that everything is ok. I arrived the SharePoint Online Authentication window in the WebBrowser Control of the application:


Then I wrote my e-mail as I usually do when I access through any other browser. And here comes the difference between a standard SharePoint Online Authentication through Forms and a SharePoint Online federated with an Active Directory using ADFS 2.0 to access using Windows Authentication credentials. The password field comes disable and you have to click on “Sign in at mydomain.com” to reach your windows authentication emergent window.


And the result using the MSDN code sample as It comes is: “This program cannot display the webpage


Why!? Everything seems to work like a charm but not if you need your Windows Authentication appear there.

Debugging the sample code I found the issue that was because of a property of the WebBrowser Control that shows the authentication form. This control is created in the ClaimsWebAuth constructor. In the code below you can see that the ScriptErrorSuppressed property is set to true in the sample code:

this.webBrowser = new WebBrowser();
this.webBrowser.Navigated += new WebBrowserNavigatedEventHandler(ClaimsWebBrowser_Navigated); 
this.webBrowser.ScriptErrorsSuppressed = true;
this.webBrowser.Dock = DockStyle.Fill;

That property prevents the WebBrowser Control to show any JavaScript error actively but unfortunately also prevents the Windows Authentication window to be shown when It’s supposed to be.

So, assuming that the ScriptErrorsSuppressed property is set by default to “false” just removing or commenting that line we have everything done.

this.webBrowser = new WebBrowser();
this.webBrowser.Navigated += new WebBrowserNavigatedEventHandler(ClaimsWebBrowser_Navigated); 
this.webBrowser.Dock = DockStyle.Fill;

Resulting in that beautiful authentication window instead of the error I showed above


I hope the code sample will be fixed soon since many people is using it as good while they only try with standard user and password login for SharePoint Online and some apps are including this bug by mistake…

In the meanwhile I fixed it and you can download the code sample fixed from this link Remote Authentication in SharePoint Online Using the Client Object Model FIXED



SolidQ suministra servicios para plataformas Microsoft que le ayudan a diseñar, integrar y optimizar su utilización de datos