Frage

is there any way authenticate by node js ? i want to use node web api using sharepoint 2013 auth by username and password.after user login i will reach sharepoint lists for crud operations. i used node-sp-auth but these codes doesnt work for me. still i am getting 401 error code.

spauth .getAuth('http://domain', { username: 'username', password: 'pass1', host: 'domain' }) .then(data => { let headers = data.headers; headers['Accept'] = 'application/json;odata=verbose'; let requestOpts = data.options; requestOpts.json = true; requestOpts.headers = headers; requestOpts.url = "http://domain/_api/web/lists/getbytitle('cari')/Items?"; request.get(requestOpts).then(response => { console.log(response.d.Title); }) })

War es hilfreich?

Lösung

Consider sp-request module. It does all authentication for you. You can use REST API without thinking about the auth:

import * as sprequest from 'sp-request';
let spr = sprequest.create(credentialOptions);
spr.get('http://sp2013dev/sites/dev/_api/web/lists/GetByTitle(\'TestList\')')
  .then(response => {
    console.log('List Id: ' + response.body.d.Id);
  })
  .catch(err =>{
    console.log('Ohhh, something went wrong...');
  });
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top