SharePoint Foundation 2010 Client Object Model Authentication
Asked Answered
S

2

3

I want to implement a custom logging by passing authentication information, as shown in below reference links:

I'm using below code but it does not automatically login instead it just popup the login window to enter username and password. I want to automatically log in by passing the credentials pro grammatically.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using System.Net;
using MSDN.Samples.ClaimsAuth;

namespace Sp_Ctx
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            //if (args.Length < 1) { Console.WriteLine("SP_Ctx <url>"); return; }

            string targetSite = "https://mysite.sharepoint.com";//args[0];
            using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite))
            {
                if (ctx != null)
                {
                    ctx.Credentials = new NetworkCredential("[email protected]", "password", "mysite.sharepoint.com");
                    ctx.Load(ctx.Web); // Query for Web
                    ctx.ExecuteQuery(); // Execute
                    Console.WriteLine(ctx.Web.Title);
                }
            }
            Console.ReadLine();
        }
    }
}

UPDATE:

I've hosted a MS 365 sharepoint 2013 site but i want to use the version 2010 authentication mechanism.

Sightseeing answered 1/4, 2013 at 2:54 Comment(2)
Please have a look at this URL. And Please let me know if it helped vrdmn.blogspot.com.au/2013/01/…Sacral
That was the very first example i tried :)Sightseeing
S
0

The MSDN sample project that you're using will only allow claims-based authentication via a pop-up. To do this programmatically, I used a different helper library, Wictor Wilén's claims demo. You can then use his MsOnlineClaimsHelper class to authenticate. Here is sample code taken directly from Wictor's blog:

MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper(url, username, password);    

using (ClientContext context = new ClientContext(url)) {

  context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;

  context.Load(context.Web);

  context.ExecuteQuery();

  Console.WriteLine("Name of the web is: " + context.Web.Title);

}

This was what I did for a project six months ago. However, I would be interested to hear if there is a new best practice or something provided by Microsoft.

Superdominant answered 23/4, 2014 at 20:28 Comment(0)
I
0

Try this:

ctx.Credentials = new NetworkCredential("guest", "password", "mysite.com.au");

The Domain in the credentials should be the domain of your guest account instead of sharepoint server name.

Industrials answered 3/10, 2014 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.