{"library":"node-sp-auth-config","title":"SharePoint Authentication Configuration Builder","description":"node-sp-auth-config is a utility package designed to simplify the creation and management of authentication configuration files for the node-sp-auth library, which handles unattended HTTP authentication to SharePoint from Node.js applications. It provides a wizard-like interactive CLI experience (`sp-auth`) and a programmatic API for building authentication options. The library supports a wide range of SharePoint versions, including SharePoint Online, 2019, 2016, 2013, and 2010, along with various authentication methods such as user credentials (SAML/ADFS, NTLM), Add-In Only permissions, and Form-Based Authentication. By default, it encrypts sensitive data like passwords using a machine-bound hash. The current stable version is 3.0.5 and it regularly releases updates in conjunction with its core dependency, node-sp-auth. Its primary differentiator is streamlining the often complex setup of SharePoint authentication credentials into a guided, persistent configuration process.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-sp-auth-config"],"cli":{"name":"sp-auth","version":null}},"imports":["import { AuthConfig } from 'node-sp-auth-config';","const { AuthConfig } = require('node-sp-auth-config');","npx sp-auth init --path ./config/my.json"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { AuthConfig } from 'node-sp-auth-config';\nimport * as path from 'path';\nimport * as fs from 'fs';\n\n// This quickstart demonstrates how to programmatically use node-sp-auth-config\n// to generate authentication options in a non-interactive, headless mode.\n// In a real scenario, the environment variables would hold your actual credentials.\n// The generated configuration can then be passed to the 'node-sp-auth' library.\n\nasync function demonstrateAuthConfig() {\n  const configFileName = 'demonstration.config.json';\n  const configFilePath = path.join(__dirname, configFileName);\n\n  console.log(`Attempting to get SharePoint auth context in headless mode.`);\n  console.log(`Config will be saved (or updated) at: ${configFilePath}`);\n\n  try {\n    const authConfig = new AuthConfig({\n      configPath: configFilePath,\n      encryptPassword: true,\n      saveConfigOnDisk: true,\n      headlessMode: true, // Prevents interactive prompts, crucial for CI/CD or automated scripts\n      authOptions: { // Provide example authOptions for headless mode\n        siteUrl: process.env.SP_SITE_URL ?? 'https://yourtenant.sharepoint.com/sites/dev',\n        strategy: 'UserCredentials',\n        username: process.env.SP_USERNAME ?? 'your.user@yourtenant.onmicrosoft.com',\n        password: process.env.SP_PASSWORD ?? 'YourVerySecretPassword123!',\n      }\n    });\n\n    const context = await authConfig.getContext();\n    console.log('\\n--- Configuration Context Retrieved ---');\n    console.log(JSON.stringify(context, null, 2));\n    console.log('\\nThese are the authentication options to pass to node-sp-auth:');\n    console.log(JSON.stringify(context.authOptions, null, 2));\n\n    if (fs.existsSync(configFilePath)) {\n      console.log(`\\nConfig file was saved/updated at: ${configFilePath}`);\n      // For a clean demonstration, you might remove the file afterward:\n      // fs.unlinkSync(configFilePath);\n      // console.log(`Cleaned up temporary config file: ${configFilePath}`);\n    } else {\n      console('\\nNo new config file was explicitly saved as it was run in headlessMode with provided authOptions.');\n    }\n\n  } catch (error) {\n    console.error('Error in authentication configuration process:', error instanceof Error ? error.message : error);\n  }\n}\n\ndemonstrateAuthConfig();\n","lang":"typescript","description":"Demonstrates how to programmatically initialize `node-sp-auth-config` to retrieve SharePoint authentication options. It shows a non-interactive setup using pre-defined credentials, suitable for CI/CD environments, and how the resulting `authOptions` can be used with `node-sp-auth`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}