How do I pass user credentials from the console to SharePoint Online?
16,485
I think the method with which you are trying to authenticate is outdated. The SharePoint 2013 Client Object Model now has a class called SharePointOnlineCredentials
which abstracts away all the tedious cookie container stuff. E.g.:
using (ClientContext clientContext = new ClientContext("https://yoursite.sharepoint.com/"))
{
SecureString passWord = new SecureString();
clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", passWord);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
Console.WriteLine(web.Title);
Console.ReadLine();
}
Please refer to this link for more information: https://sharepoint.stackexchange.com/questions/83985/access-the-sharepoint-online-webservice-from-a-console-application
Related videos on Youtube
Author by
sdg
Updated on June 04, 2022Comments
-
sdg almost 2 years
I am trying to connect SharePoint 2013 Online website using a Context Token from a console executable. However, it is giving me error
The remote server returned an error: (403) Forbidden.
Here is the code snippet:
string spurl = ConfigurationManager.AppSettings["Sharepoint_URL"].ToString(); using (ClientContext context = new ClientContext(spurl)) { context.Credentials = new NetworkCredential("username", "password", "domain"); context.ExecuteQuery(); Web web = context.Web; context.Load(web); context.ExecuteQuery(); Console.WriteLine(context.Web.Title); } Console.ReadKey();
How can I make a connection with SharePoint Online? Does it only support claims-based authentication?
-
Wout almost 10 yearsTo create the password in the passWord object : foreach (char c in "yourpassword".ToCharArray()) passWord.AppendChar(c);