CRM 2011 – authenticating with Sharepoint Online 2010 from a .NET

I was having a struggle to authenticate with Sharepoint Online

I was using the Client Object Model and when I was trying to create a connection to sharepoint so I could check if folders had been added for CRM but I was getting a 403 forbidden message.

In the back of mind I was thinking the problem had to be linked to SharePoint/Office 365 online which both need you to login.

This page has a good overall description of the problem, you basically need to authenticate before you can start using SharePoint 2010 Online

Remote Authentication in SharePoint Online Using Claims-Based Authentication

http://msdn.microsoft.com/en-us/library/hh147177.aspx

The only problem with code I got from here is it popped up a login if the authenticated cookies were not on the machine.  As my code would be running from a plugin I needed to automate that

Authentication with SharePoint Online and the Client Side Object Model

http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx

this code works

Part 2: “Headless” Authentication with SharePoint Online and the Client Side Object Model

http://blogs.msdn.com/b/cjohnson/archive/2011/05/14/part-2-headless-authentication-with-sharepoint-online-and-the-client-side-object-model.aspx

one gotcha to mention with the code above is you have to put on the forward slash at the end of the SharePoint url

e.g.

https://<companyname&gt;.sharepoint.com/

if you don’t put the forward slash on it won’t work.

I also had problems because my pc clock was over 5 minutes out, it wasn’t letting me login.

some other useful links regarding writing .Net code for SharePoint 2010

Common Programming Tasks in the Managed Client Object Model

http://msdn.microsoft.com/en-us/library/ee537013.aspx