Issue with Client Credentials Authentication on Solid with @inrupt/solid-client-authn-node

Hi everyone,

I am trying to implement authentication using the Client Credentials flow to access a Solid Pod via the @inrupt/solid-client-authn-node library, but I am encountering some difficulties. Let me explain what I’m trying to do and where I’m getting stuck.

What I want to do:

My goal is to authenticate using client credentials (client ID and client secret) to obtain an access token that will allow me to interact with a Solid Pod without requiring direct user action. I want to do this using the Client Credentials flow (authentication without a user).

What I’ve done:

  1. I have configured the environment variables (client ID, client secret, and OIDC issuer) in my .env file.
  2. I used the login() method from the Session class provided by the @inrupt/solid-client-authn-node library to perform authentication.
  3. I created a small script that performs the login and prints the access token if authentication is successful.

Here is the code I’m using:

typescript

import { Session } from "@inrupt/solid-client-authn-node";
import dotenv from "dotenv";

// Load environment variables
dotenv.config();

async function authenticateWithClientCredentials() {
  const session = new Session();

  try {
    // Perform login with client credentials
    await session.login({
      clientId: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      oidcIssuer: process.env.OIDC_ISSUER,
    });

    console.log("Authentication completed!");

    // Check if the session is logged in successfully
    if (session.info.isLoggedIn) {
      console.log("Authenticated successfully!");

      // Get the access token
      const accessToken = session.info.accessToken;

      // Debug: Log to see what happens with the access token
      if (accessToken) {
        console.log("Access Token:", accessToken);
      } else {
        console.log("Access Token not available. Check the configuration.");
      }
    } else {
      console.log("Authentication failed. Check the flow.");
    }
  } catch (error) {
    if (error instanceof Error) {
      console.error("Error during authentication:", error.message);
    } else {
      console.error("Unknown error during authentication.");
    }
  }
}

authenticateWithClientCredentials();

The issue:

  • When I run the code, I get the message “Authentication completed!” but I never manage to get the access token. It prints “Access Token not available. Check the configuration.”
  • There doesn’t seem to be any obvious error in the configuration (client ID, client secret, and OIDC issuer are correct), but the authentication isn’t returning the token.

What I’ve tried:

  • I verified that the environment variables are loaded correctly (I’m using dotenv to load them).
  • I added an error type check, but there doesn’t seem to be any error during the login phase.

Question:

Has anyone faced a similar issue? How can I ensure that the access token is correctly returned after login?

Any suggestions are welcome!

Thanks in advance!

From the docs, I don’t believe there is an accessToken property available on the Session type.

So, if it’s not possible to obtain an access token, does that mean I can’t replicate a request using Postman or Swagger?

You can get the access token, you would just need to capture the raw response JSON body and get the “access_token” key.