Many Solid use cases — automated data pipelines, bots, CI/CD tasks, and server-to-server integrations — require authentication without a browser. This guide walks you through authenticating a Node.js script against a Solid server using Client Credentials.
The approach works with any Solid server that supports the Client Credentials grant type, including the Community Solid Server (CSS) and Inrupt's Enterprise Solid Server (ESS).
- Node.js v18 or later (for built-in
fetch) - A Solid account with a Pod on a server that supports Client Credentials
- Basic familiarity with JavaScript
The flow has three stages:
- Generate a Client Credentials token — obtain a
client_id/client_secretpair linked to your WebID. This only needs to be done once. - Log in with the credentials — use the
client_idandclient_secretto start an authenticated session. - Make authenticated requests — use the session's
fetchto read and write resources on your Pod.
Create a new directory and initialize it:
mkdir solid-script && cd solid-script
npm init -ySet the project to use ES modules and install the required library:
npm pkg set type=module
npm install @inrupt/solid-client-authn-nodeCreate a file called index.js — all the code below goes into this file.
Before your script can log in, you need a client_id / client_secret pair. There are two ways to get one:
If your Solid server has an account management UI, you can create a token there:
- Navigate to your account page:
- Community Solid Server (local): http://localhost:3000/.account/
- solidcommunity.net: https://solidcommunity.net/.account/
- Inrupt PodSpaces: https://login.inrupt.com/registration.html
- Create a new Client Credentials token, giving it a name and selecting your WebID.
- Copy the
idandsecretvalues shown. Store the secret safely — it cannot be retrieved again.
Skip ahead to Step 3 if you use this approach.
Some Solid servers also allow you to generate credentials programmatically. This is useful for automation or when you don't have browser access. The process is server-specific — for example, the Community Solid Server provides a dedicated API for this:
Once you have a client_id and client_secret, you can authenticate using the Session class from @inrupt/solid-client-authn-node.
Replace the contents of index.js (or create a new file) with:
import { Session } from '@inrupt/solid-client-authn-node';
// These values come from Step 2 (or from your account page).
// In production, load these from environment variables.
const CLIENT_ID = process.env.SOLID_CLIENT_ID;
const CLIENT_SECRET = process.env.SOLID_CLIENT_SECRET;
const OIDC_ISSUER = process.env.SOLID_OIDC_ISSUER; // Your Solid server URL
async function main() {
// Create a new session and log in
const session = new Session();
await session.login({
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
oidcIssuer: OIDC_ISSUER,
});
if (!session.info.isLoggedIn) {
throw new Error('Login failed');
}
console.log(`Logged in as ${session.info.webId}`);
// session.fetch works just like the standard fetch API,
// but automatically includes authentication headers.
const response = await session.fetch(session.info.webId);
console.log(`GET ${session.info.webId} — ${response.status}`);
console.log(await response.text());
// Always log out when done
await session.logout();
console.log('Logged out.');
}
main().catch(console.error);Run the script, passing your credentials and server URL as environment variables.
On Linux / macOS (Bash):
SOLID_CLIENT_ID="your-client-id" \
SOLID_CLIENT_SECRET="your-client-secret" \
SOLID_OIDC_ISSUER="http://localhost:3000" \
node index.jsOn Windows (PowerShell):
$env:SOLID_CLIENT_ID="your-client-id"
$env:SOLID_CLIENT_SECRET="your-client-secret"
$env:SOLID_OIDC_ISSUER="http://localhost:3000"
node index.jsReplace http://localhost:3000 with the URL of your Solid server (for example, https://solidcommunity.net or https://login.inrupt.com).
You should see your profile document printed to the console.
- Token reuse: The
client_id/client_secretpair does not expire. Generate it once and reuse it across runs. Only the access tokens obtained duringsession.login()are short-lived — the library handles refreshing them automatically. - Session keep-alive: By default, the
Sessionrefreshes its tokens in the background. Pass{ keepAlive: false }to theSessionconstructor if you want a one-shot script that exits cleanly. - Security: Never hard-code secrets in source code. Use environment variables or a secrets manager.
- Multiple WebIDs: You can generate multiple client credentials tokens, each linked to a different WebID on your account.