forked from pRatikSathaye/sharepoint-auth
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
46 lines (41 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var Sharepoint = require('./sharepoint'),
request = require('./request').request,
options = {
auth: {
username: '<username>@<your-domain>.onmicrosoft.com',
password: '<password>'
},
host: 'https://<your-domain>.sharepoint.com'
};
Sharepoint(options, function(err, result) {
if (err) {
console.log('Err ', err);
} else {
/*
* Cookie values and request digest
* result.cookies.FedAuth
* result.cookies.rtFa
* result.requestDigest
*/
var requestOptions = {
url: options.host + '/_api/web/lists',
method: 'GET',
headers: {
'Cookie': 'FedAuth=' + result.cookies.FedAuth + ';rtFa=' + result.cookies.rtFa + ';',
'X-RequestDigest': result.requestDigest
},
json: true,
followAllRedirects: true
}
request(requestOptions)
.then(function(resp) {
console.log('Response', resp.body);
})
.error(function(err) {
console.log('Error', err);
})
.catch(function(exception) {
console.log('Exception', exception);
})
}
});