0
votes

I am calling the SharePoint 2010 REST/ODATA api and by default the data context uses DefaultCredentials, which is really the logged-in user of my Asp.Net application. If I don't attach DefaultCredentials to the context, then I just get 401 Unauthorized.

I was wondering how to call SharePoint API while using the Application Pool credentials? I am trying to follow the trusted systems security approach. Otherwise the SharePoint site needs to grant ODATA access and certain lists need be writable by basically everyone (gak!).

For example, with a SQL connection, I would just set "Integrated Security=true" to use the application pool credentials.

1

1 Answers

0
votes

Am I right that you are running an ASP.NET application on other than the SharePoint server? (Outside of the farm; just a machine with IIS and ASP.NET.) If your ASP.NET application pool runs under the same user as your SharePoint web application you can temporarily impersonate the code of you handler or page to the application pool user and use the default network credentials:

using (HostingEnvironment.Impersonate()) {
    ICredentials credentials = CredentialCache.DefaultNetworkCredentials;
    // ... use the credentials
}

If you know credentials (name and password) of the application pool user from some configuration you can make the HTTP request using them directly:

ICredentials credentials = new NetworkCredential("user_name", "password");
// ... use the credentials

--- Ferda