Thursday, November 8, 2012

Authentication types in CSOM



In CSOM coding whenever you write any application for share point data operation then it first goes for your default windows credentials.When you are accessing SharePoint data from any other client computer then you need to specify credential details in code.
Basically there are three authentication choice  that you can use when you’re working with the Client Object Model in SharePoint 2010:

Anonymous
 Default
 Forms based Authentication

You can specify clientContext.Authentication = Anonymous\Default\FormsAuthentication
If you do not choose an authentication method in your code, the application will default to using the client’s Windows Credentials (DefaultCredentials). If you are trying to access sharepoint remotely using client application you will have to pass proper credentials.


Below is the code for each type

Windows Network credentials
NetworkCredential credentials = new NetworkCredential(“username”, “password”, “domainname”);

Anonymous access Authentication
clientcontext.AuthenticationMode = SP.ClientAuthenticationMode.Anonymous;

Form Based Authentication
SP.FormsLoginInfo fbaLogin = new SP.FormsAuthenticationLoginInfo(“Suryakant”, “Hmmm”);
clientcontext.AuthenticationMode = SP.ClientAuthenticationMode.FormsAuthentication;
clientcontext.FormsAuthenticationLoginInfo = fbaLogin;

2 comments:

Jiniv Thakkar said...

Thanks ! this post is to the point

Gopal Shinde said...

Thanks...