Monday, August 29, 2011

Client Object Model – Part 12

We are going to end this series of client object model with this post. There are so many things that we can do with the help of any of the three client object model methods. It is the matter of experience and doing practices only. Keep trying more things on your own and do let us know if you get stuck somewhere.

In this post, we are going to discuss on one very important aspect of client object model. But before that if you have not gone through Part 1 to Part 11, I would recommend reading them first and then continue reading from here.

You must have thought that in none of the series we talked about authentication. How does a client object model connects with the respective objects on the server like lists, sites, libraries, workflows etc.?


There are three methods.
1) Default authentication
2) Forms authentication
3) Anonymous authentication


And we have managed client object model, Silverlight client object model and ECMA script object model.


Managed COM – Windows authentication is default authentication.
So we do not need to explicitly specify anything. When we do not specify anything, it connects with our windows credentials and then checks our access on objects that we access through object model.

So we need to be very careful while writing a code that when the code runs, user should have a sufficient privilege on objects.

We can use anonymous or forms authentication with managed COM.

Silverlight COM – Same as Managed COM.

ECMA COM - Do not need any authentication. It runs inside the browser page and hence by default it has passed the parent authentication method.

Setting the Forms bases authentication on COM

If we use Forms authentication, then we need to set one more property which is AuthenticationMode on clientcontext object.

Plus we also need to make an instance of FormsAuthenticationLoginInfo class and assign the username and password before accessing or performing any operation on any SharePoint object and then set that authentication object to client context object.


FormsAuthenticationLoginInfo objformsAuth = new
FormsAuthenticationLoginInfo("UserName", "Password");

clientContext.FormsAuthenticationLoginInfo = objformsAuth;

Setting the Anonymous authentication on COM

ClientContext.AuthenticationMode = ClientAuthenticationMode.Anonymous;

Do remember that when using this method, object which you are trying to access in code should have anonymous permission assigned.


2 comments:

Unknown said...

for Silverlight client OM, and you want to allow anonymous access to sharepoint data, you need to run the following PoweShell commands

$webapp = Get-SPWebApplication “http://URL”
$webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], “GetItems”)
$webapp.Update()

hope this help :)

Mahmoud
Exceed IT Services -UAE

Unknown said...

for Silverlight client OM, and you want to allow anonymous access to sharepoint data, you need to run the following PoweShell commands

$webapp = Get-SPWebApplication “http://URL”
$webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], “GetItems”)
$webapp.Update()

hope this help :)

Mahmoud
Exceed IT Services -UAE




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com