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

**URL:** https://forum.solidproject.org/t/issue-with-client-credentials-authentication-on-solid-with-inrupt-solid-client-authn-node/9200
**Category:** General Discussion
**Created:** [March 28, 2025, 4:34pm UTC](https://forum.solidproject.org/t/issue-with-client-credentials-authentication-on-solid-with-inrupt-solid-client-authn-node/9200 "2025-03-28T16:34:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zepek081](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/zepek081/32/4598_2.png) [@zepek081](https://forum.solidproject.org/u/zepek081)
#### Post date: [March 28, 2025, 4:34pm UTC](https://forum.solidproject.org/t/issue-with-client-credentials-authentication-on-solid-with-inrupt-solid-client-authn-node/9200/1 "2025-03-28T16:34:56Z")

</div>

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

```auto
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!

---

<div class="post-metadata">

### Author: ![gaz009](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@gaz009](https://forum.solidproject.org/u/gaz009)
#### Post date: [March 28, 2025, 5:38pm UTC](https://forum.solidproject.org/t/issue-with-client-credentials-authentication-on-solid-with-inrupt-solid-client-authn-node/9200/2 "2025-03-28T17:38:53Z")

</div>

From the [docs](https://docs.inrupt.com/developer-tools/api/javascript/solid-client-authn-node/interfaces/ISessionInfo.html#properties), I don’t believe there is an accessToken property available on the Session type.

---

<div class="post-metadata">

### Author: ![zepek081](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/zepek081/32/4598_2.png) [@zepek081](https://forum.solidproject.org/u/zepek081)
#### Post date: [March 31, 2025, 3:08pm UTC](https://forum.solidproject.org/t/issue-with-client-credentials-authentication-on-solid-with-inrupt-solid-client-authn-node/9200/3 "2025-03-31T15:08:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gaz009](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@gaz009](https://forum.solidproject.org/u/gaz009)
#### Post date: [March 31, 2025, 11:02pm UTC](https://forum.solidproject.org/t/issue-with-client-credentials-authentication-on-solid-with-inrupt-solid-client-authn-node/9200/4 "2025-03-31T23:02:53Z")

</div>

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