SharePointAds TextOnly

Wednesday, 16 November 2011

SharePoint online SUBSITE authentication using client object model :

Are you looking for the perfect solution to authenticate and get data from SharePoint online subsite 2010 (SPO) using client object model?
You can find following sample projects to connect authenticate SharePoint online site content using client object model,
This article has given brief overview of claims-based authentication and client object model for remote authentication in SharePoint Online. You can download sample code which demonstrates technique of adding SharePoint authentication cookies to the ClientContext object. Solution prompted a dialog window where user have to enter their Office 365 credentials, use the same cookies to the SharePoint client side object model (CSOM) to get SharePoint site content.

But what should I do when I don’t want to show prompt form to enter user details, because I am accessing sharepoint content in Azure site. So I started to check the solution where I can provide user credentials from the code.

This sample queries the Office 365 STS directly using the Windows Identity Foundation (WIF).  WIF helps with managing the security tokens and requests to the STS.

Great! This is what exactly I was looking for, it is very good solution.
Project executable solution works fine with the root site. I was trying to query for SharePoint online subsite using the same code but giving (404) NOT Found error for Subsites . When I debugged the code, found following line

Wreply = samlUri.GetLeftPart(UriPartial.Authority) + "/_forms/default.aspx?wa=wsignin1.0"

For root site it gets the correct reference like and if you used same code to query SharePoint subsite it will give you (404) Not Found because if you try to browse browser will show 404 not found error.

Make following changes on ‘MsOnlineClaimsHelper.cs’ file,
- Find following line in CS file,
Wreply = _samlUrl  + "/_forms/default.aspx?wa=wsignin1.0"

- Update same file with following changes

Uri samlUri  = new Uri(_samlUrl);
var sharepointSite = new
Wctx = office365Login,
Wreply = samlUri.GetLeftPart(UriPartial.Authority) + "/_forms/default.aspx?wa=wsignin1.0"

Above changes works for me! Let me know if you want any more information.