{"library":"node-sp-auth","title":"SharePoint Unattended HTTP Authentication","description":"node-sp-auth is a JavaScript/TypeScript library designed for performing unattended (non-interactive) HTTP authentication against SharePoint environments, supporting SharePoint 2013 and newer, as well as SharePoint Online. It automatically determines the appropriate authentication strategy (e.g., NTLM, FBA, SAML, ADFS, Add-in only) based on provided credentials and handles credential caching for performance. The current stable version is 3.0.9. However, the package is no longer actively maintained, with no new features or versions expected. Developers are strongly advised to migrate to `@azure/msal-node` for modern SharePoint Online authentication, especially as some authentication methods, particularly those relying on the SharePoint Add-in model, will cease to function after April 2026 due to Microsoft's retirement of Azure ACS and the Add-in model.","language":"javascript","status":"deprecated","last_verified":"Thu Apr 23","install":{"commands":["npm install node-sp-auth"],"cli":null},"imports":["import * as spauth from 'node-sp-auth';","import * as spauth from 'node-sp-auth';\nconst authOptions = await spauth.getAuth(url, credentials);","const spauth = require('node-sp-auth');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as spauth from 'node-sp-auth';\nimport * as request from 'request-promise'; // Ensure request-promise is installed\n\nasync function authenticateAndFetch() {\n  const url = process.env.SP_SITE_URL ?? 'https://yourtenant.sharepoint.com/sites/dev';\n  const username = process.env.SP_USERNAME ?? '';\n  const password = process.env.SP_PASSWORD ?? '';\n\n  if (!username || !password) {\n    console.warn(\"SP_USERNAME or SP_PASSWORD environment variables are not set. This example might fail without proper credentials.\");\n  }\n\n  const credentialOptions = {\n    username: username,\n    password: password\n    // Add other credential options (e.g., tenant ID, client ID, client secret) as needed\n    // for specific authentication types like SAML or ADFS.\n  };\n\n  try {\n    const authResult = await spauth.getAuth(url, credentialOptions);\n\n    const headers = authResult.headers;\n    headers['Accept'] = 'application/json;odata=verbose';\n\n    console.log('Authentication successful. Making request...');\n\n    const response = await request.get({\n      url: `${url}/_api/web`,\n      headers: headers,\n      // IMPORTANT: For NTLM authentication, pass the 'agent' property if it exists\n      agent: authResult.options?.agent\n    });\n\n    console.log('Successfully fetched web data:');\n    console.log(JSON.parse(response));\n\n  } catch (error) {\n    console.error('Authentication or request failed:', error);\n  }\n}\n\nauthenticateAndFetch();","lang":"typescript","description":"This example demonstrates how to use `node-sp-auth` to obtain authentication headers for a SharePoint site and then use them with `request-promise` to fetch data from the SharePoint REST API.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}