Export (0) Print
Expand All

Authentication in the Managed Client Object Models

SharePoint 2010

Last modified: July 15, 2010

Applies to: SharePoint Foundation 2010

Available in SharePoint Online

By default, the managed client object models authenticate users by using their Windows credentials (DefaultCredentials). Optionally, you can change the authentication mode on the ClientContext object, and specify the use of Forms authentication when the server supports Forms authentication. A user must then supply a user name and password through properties on the client context object. Behind the scenes, Microsoft SharePoint Foundation 2010 calls the [Authentication Web service], obtains the correct cookie, and then makes the necessary object model calls. To run managed client code against a Forms authentication server, you must change to Forms authentication. This requirement does not apply to the JavaScript object model.

The managed client object models provide a ClientAuthenticationMode enumeration whose values are Anonymous, Default, and FormsAuthentication. To specify Forms authentication, use code similar to the following.

clientContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

In addition to setting the authentication mode, you must specify the user name and password information, as shown here.

FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo("MyUser", "MyPassword");

clientContext.FormsAuthenticationLoginInfo = formsAuthInfo;
NoteNote

In the example, if the account name and password contained in formsAuthInfo are sent in clear text, you must use HTTPS protocol instead of HTTP.

Show:
© 2014 Microsoft