Is there a way to connect to SharePoint Online from Web client javascript (js-code embedded in an .aspx page
).
How can I authenticate ?
How can I access list item objects such as library documents from my client JavaScript code (if possible)?
Sounds as if you want to connect a local ASP.NET App to your SharePoint Online (I am making a lot of assumptions in my answer based on this). If this is true, you would need to impersonate a SharePoint Online user in the application code by setting the network credentials to the username and password of the SharePoint Online user account then connect to the web services and pull the data using JSOM and LINQ to work with the results once received. I have done this approach not with SharePoint Online but with a public facing SharePoint Server that was in a different domain (Been a long while but should be same in concept). A LOT of issues to consider both with security and availability with this approach, I would make sure you must do it this way before committing to it. Below is some code to look at and examine hope it helps (Note: I would put the Username and Password in the web.config file as a app setting key value pair and encrypt/decrypt in the code for production just like you would with any SQL style external data connection, also I apologize for the weird x's in the code I had to redact it to post here):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using x_GetExecApprover.xWebService;
namespace x_GetExecApprover
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ProcedureCall(String inExecApprover, String inExecApprovalDate, String inxID)
{
ProcedureLbl.Text = inExecApprover + ", " + inExecApprovalDate + ", " + inxID;
}
protected void SubBtn_Click(object sender, EventArgs e)
{
try
{
String lclExecApprover = null;
String lclExecApprovalDate = null;
String lclxID = xIdTxtBx.Text;
if (xIdTxtBx.Text.Length != 0)
{
xManagementApprovalSystemDataContext dc = new xManagementApprovalSystemDataContext(new Uri("https://xxx.sharepoint.com/_vti_bin/ListData.svc"));
System.Net.NetworkCredential credentials = new NetworkCredential("UserName", "Password");
dc.Credentials = credentials;//CredentialCache.DefaultNetworkCredentials;
var query = from xApprovalsItem x_RowItems in dc.xApprovals
where x_RowItems.xID.Equals(lclxID) && x_RowItems.CurrentLocation.Equals("complete")
orderby x_RowItems.ExecutiveApprovalDate descending
select new
{
ExecApprover = x_RowItems.ExecutiveApprover,
ExecApprovalDate = x_RowItems.ExecutiveApprovalDate
};
ResultsGrid.DataSource = query;
ResultsGrid.DataBind();
foreach (var item in query)
{
lclExecApprover = item.ExecApprover;
lclExecApprovalDate = item.ExecApprovalDate;
break;
}
ProcedureCall(lclExecApprover, lclExecApprovalDate, lclxID);
}
}
catch
{
Response.Write("Error");
}
}
}
}