I am calling piece of code from SP2013 workflow as a web service. It is not important what code does, it is important that it works only when I write user credentials explicitly, which is not good.
So, if I do this:
ClientContext ctx = new ClientContext("mySite");
NetworkCredential credentials = new NetworkCredential("myUser", "myPass", "myDomain");
ctx.Credentials = credentials;
ICredentials cred;
Site site1 = ctx.Site;
Web web = ctx.Web;
UserCollection coll = web.SiteUsers;
ctx.Load(coll);
ctx.ExecuteQuery();
foreach (User user in coll) {
if (user.IsSiteAdmin) {
cred = user.Context.Credentials;
ctx.Credentials = cred;
}
}
It works (but, I gave the user's password here), but if I replace line:
NetworkCredential credentials = new NetworkCredential("myUser", "myPass", "myDomain");
with:
NetworkCredential credentials = CredentialCache.DefaultNetworkCredentials;
it doesn't work. How can I execute my code without passing the password of the user?