@@ -29,10 +29,10 @@ The current version supports SharePoint Online CSOM library (v 16) The remote au
2929
3030# Usage
3131
32+ ** Authentication**
3233
33- ** Examples **
34+ Authenticate with _ user credentials _
3435
35- The fisrt example demonstrates how to read SP.Web object:
3636
3737````
3838var csomapi = require('csom-node');
@@ -65,6 +65,41 @@ authCtx.acquireTokenForUser(settings.username, settings.password, function (err,
6565
6666````
6767
68+ Authenticate with _ app principal_ credentials (client id & client secret)
69+
70+ ````
71+ var csomapi = require("csom-node");
72+
73+ var settings = {
74+ url: "https://contoso.sharepoint.com/",
75+ clientId: "YOUR-GUID-GOES-HERE",
76+ clientSecret: "YOUR-CLIENT-SECRET-GOES-HERE"
77+ };
78+
79+ csomapi.setLoaderOptions({url: settings.url}); //set CSOM library settings
80+
81+ var authCtx = new AuthenticationContext(settings.url);
82+ authCtx.acquireTokenForApp(settings.clientId, settings.clientSecret, function (err, data) {
83+
84+ var ctx = new SP.ClientContext("/"); //set root web
85+ authCtx.setAuthenticationCookie(ctx); //authenticate
86+
87+ //retrieve SP.Web client object
88+ var web = ctx.get_web();
89+ ctx.load(web);
90+ ctx.executeQueryAsync(function () {
91+ console.log(web.get_title());
92+ },
93+ function (sender, args) {
94+ console.log('An error occured: ' + args.get_message());
95+ });
96+
97+ });
98+
99+ ````
100+
101+ ** Working with List Items**
102+
68103The following example demonstrates how to perform CRUD operations against list items:
69104
70105
0 commit comments