Solid Command-Line Authentication Client
solid-auth-cli is a Node.js and command-line client library designed to facilitate persistent authentication with Solid Pods. It provides an API that mirrors solid-auth-client, enabling scripts to function in both browser (via solid-auth-client) and server-side/CLI environments (via solid-auth-cli) with minimal code changes. The current stable version is 1.0.15. While a specific release cadence isn't detailed, its versioning suggests a mature and stable 1.x branch. A key differentiator is its support for persistent logins using configuration files or environment variables, making it ideal for automated scripts or server-side applications that interact with Solid resources. It also offers a custom fetch implementation that can be integrated with rdflib.js (version 0.19.1 or newer) for graph data manipulation, or used directly for fetching resources via standard REST APIs, allowing programmatic interaction with the Solid ecosystem.
Common errors
-
TypeError: rdflib_1.default.fetcher is not a function
cause Attempting to use `rdflib.js` with `solid-auth-cli` when `rdflib.js` is an older, incompatible version (prior to 0.19.1).fixUpgrade `rdflib.js` to version 0.19.1 or newer: `npm install rdflib@^0.19.1`. -
ReferenceError: require is not defined
cause You are attempting to use the `require()` function in an ES Module (ESM) context in Node.js, where `import` is expected.fixEnsure your project's `package.json` specifies `"type": "commonjs"`, or rename your file to `.cjs`. Alternatively, wrap `solid-auth-cli` in a CJS file or use dynamic `import()` if truly in an ESM context. -
Error logging in: No Identity Provider, username, or password found.
cause The `login()` method was called without sufficient credentials or configuration. It expects either an object with `idp`, `username`, `password`, a path to a credentials JSON file, or environment variables `SOLID_IDP`, `SOLID_USERNAME`, `SOLID_PASSWORD` to be set.fixProvide credentials directly to `login({ idp: '...', username: '...', password: '...' })`, or create a `~/.solid-auth-cli-config.json` file, or set the necessary environment variables before running your script.
Warnings
- gotcha When integrating with rdflib.js, solid-auth-cli requires rdflib.js version 0.19.1 or later due to API changes in rdflib's fetcher initialization.
- gotcha solid-auth-cli is a CommonJS module. Attempting to use `import` statements directly in an ES Module context will fail unless Node.js is configured for interoperability or a build step transpiles it.
Install
-
npm install solid-auth-cli -
yarn add solid-auth-cli -
pnpm add solid-auth-cli
Imports
- auth
import auth from 'solid-auth-cli'
const auth = require('solid-auth-cli') - login
import { login } from 'solid-auth-cli'auth.login()
- fetch
import { fetch } from 'solid-auth-cli'auth.fetch(resource)
Quickstart
const solid = { auth:require('solid-auth-cli') }
const resource = "https://example.com/private/hidden.ttl" // Replace with your Solid Pod resource
const expected = "only the owner"
console.log("logging in ...")
login().then( session => {
console.log(`logged in as <${session.webId}>`)
solid.auth.fetch(resource).then( response => {
if (!response.ok) console.log(response.status+" "+response.statusText)
response.text().then( content => {
if( content.match(new RegExp(expected)) ) console.log("ok: content matches expected pattern.")
else console.log("Got something, but not the right thing.")
},e => console.log("Error parsing : "+e))
},e => console.log("Error fetching : "+e))
},e => console.log("Error logging in : "+e))
async function login() {
// This example attempts a silent login from a previous session, then prompts if needed.
// For a non-interactive script, ensure credentials are set via env vars or config file.
var session = await solid.auth.currentSession()
if (!session) {
// You would typically configure IDP, username, password via env vars or a config file for CLI usage
session = await solid.auth.login() // Will attempt to read ~/.solid-auth-cli-config.json or env vars
}
return session;
}