Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit 0b81fc1

Browse files
committed
README file has been updated to reflect the latest changes (SharePoint app principal credentials).
1 parent 6d98260 commit 0b81fc1

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
````
3838
var 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+
68103
The following example demonstrates how to perform CRUD operations against list items:
69104

70105

examples/settings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var settings = {
2-
tenantUrl: "https://tenant.sharepoint.com",
2+
tenantUrl: "https://mediadev19.sharepoint.com",
33
webUrl: "/", //Note:for root web set url to '/'
4-
username: "mattim@tenant.onmicrosoft.com",
4+
username: "mattim@mediadev19.onmicrosoft.com",
55
password: "P@ssw0rd"
66
};
77

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "csom-node",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "SharePoint Client Object Model (CSOM) API for node",
55
"main": "./lib/csom-loader.js",
66
"author": {

0 commit comments

Comments
 (0)