Skip to content

SharePoint on premise user credentials authentication

Sergei Sergeev edited this page Aug 8, 2017 · 2 revisions

This type of authentication uses http ntlm handshake in order to obtain authentication header.

Credential options:

  • username - required string, username
  • password - required string, password
  • domain - optional string, domain. Be aware, that either domain or workstation should be provided
  • workstation - optional string, workstation. Either domain or workstation should be provided

For this authentication I recommend using combination of username, password and domain or username, password and workstation (when there is no domain). You can also provide only username and password, but that might not work.
For example user [email protected] need to provided following recommended credential object:

{
  username: 'john.smith',
  password: 'pass',
  domain: 'contoso'
}

You can also provide

{
  username: '[email protected]',
  password: 'pass'
}

but this configuration might not work for you.

workstation option is used when you outside domain (in case of SharePoint standalone installation without domains, etc, all in one single computer).

The easiest way to find your current user's domain is to run echo %USERDOMAIN% in command line.

Resolving object:

{
  headers: {
    'Connection': 'Close',
    'Authorization': '<ntlm authorization header>'
  },
  options: {
    agent: keepaliveAgent     /* keep alive agent */
  }
}

Configuration required:

No additional configuration required, since you simply supplying user credentials.

Sample using:

import * as spauth from 'node-sp-auth';
import * as request from 'request-promise';

spauth
  .getAuth('https://sp2013dev/sites/dev/', {
    username: 'administrator',
    password: '[password]',
    domain: 'sp'
  })
  .then(data =>{
    let headers = data.headers;
    headers['Accept'] = 'application/json;odata=verbose';
    let requestOpts = data.options;
    requestOpts.json = true;
    requestOpts.headers = headers;
    requestOpts.url = 'https://sp2013dev/sites/dev/_api/web';

    request.get(requestOpts).then(response => {
      console.log(response.d.Title);
    });
  });