11

We're trying to connect to an on premise installation of SharePoint 2013 which authenticates using ADFS. Our Development was done using Office 365 installation where the following code works perfectly fine for authentication (and fetching all items from a particular list).

public void DeleteAllItemsFromCalendar(string ListName, string SiteUrl, string UserName, string Password)
{
        ClientContext content = new ClientContext(SiteUrl);
        content.Credentials = new SharePointOnlineCredentials(UserName, convertToSecureString(Password));
        content.ExecuteQuery();
        List list = content.Web.Lists.GetByTitle(ListName);
        CamlQuery query = new CamlQuery();
        query.ViewXml = "<Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query>";
        ListItemCollection allitems = list.GetItems(query);
        content.Load(allitems);
        content.ExecuteQuery();
        // do something with items.
}

Is this same code supposed to work for an in-premise SharePoint 2013 or is the "SharePointOnlineCredentials" class exclusively for Office 365 based SharePoint installations? We tried by passing the URL of the inpremise site and the credentials of an in premise site keeping the code intact and the code seems to give a “Catastrophic Error” Exception.

If the "SharePointOnlineCredentials" class is exclusively for Office 365, are there any pointers to simple ways to connect to an in premise SharePoint 2013 instance that authenticates using ADFS 2.0?

I've looked at multiple hand built solutions like this TechNet Blog but clearly none of them seem to work with SharePoint 2013.

Any help will be appreciated.

1
  • Have you got any update on this? did you manage do solve the issue?
    – Fabio
    May 13, 2015 at 15:28

1 Answer 1

2

You cannot use SharePointOnlineCredentials class. You need to get the FedAuth cookie by making a request against the ADFS server and then attach it to every CSOM request.

Update

Here are some sample values for all those parameters:

wctx = "SITEURL/_layouts/Authenticate.aspx?Source=%2F"
wreply = "SITEURL/_trust/"
stsUrl = "https://auth.your.adfs.server.com/adfs/services/trust/2005/usernamemixed"
realm = "urn:something:sharepointserver.com" //Configured in ADFS
3
  • Hi @marco, I tried implementing the solution that you linked to with SP2013, but it´s a bit of a challenge. E.g., I don´t know to put for Wctx, Wreply. Currently, it seems whatever I write for those, I get back HTTP error 405 "Method not allowed" from ADFS. Has anyone successfully done this? Jul 10, 2015 at 19:37
  • See my update with sample values
    – marco
    Jul 14, 2015 at 8:26
  • That´s a great help, @marco, thanks a lot! I will try it out and update you on the final outcome. Jul 16, 2015 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.