diff --git a/packages/node/src/Session.static.spec.ts b/packages/node/src/Session.static.spec.ts index ec415e9f93..841d4294f0 100644 --- a/packages/node/src/Session.static.spec.ts +++ b/packages/node/src/Session.static.spec.ts @@ -25,6 +25,7 @@ import { validate } from "uuid"; import type * as Jose from "jose"; import type * as OpenIdClient from "openid-client"; import { Session } from "./Session"; +import { randomUUID } from "crypto"; // Camelcase identifiers are required in the OIDC specification. /* eslint-disable camelcase*/ @@ -166,9 +167,10 @@ describe("Session static functions", () => { describe("Session.fromTokens", () => { it("creates a session with the provided tokens", async () => { + const mockedAccessToken = randomUUID(); const mockedIdToken = await mockIdToken({}); const tokenSet: SessionTokenSet = { - accessToken: "access.token.jwt", + accessToken: mockedAccessToken, idToken: mockedIdToken, clientId: mockClientId, issuer: mockOpConfig().issuer, @@ -195,7 +197,9 @@ describe("Session static functions", () => { }) as typeof fetch; await session.fetch("https://some.resource"); // @ts-expect-error We know headers is initialized. - expect(headers.get("Authorization")).toBe(`Bearer ${mockedIdToken}`); + expect(headers.get("Authorization")).toBe( + `Bearer ${mockedAccessToken}`, + ); globalThis.fetch = globalFetch; }); @@ -207,9 +211,10 @@ describe("Session static functions", () => { publicKey: await exportJWK(dpopKeyPair.publicKey), }; + const mockedAccessToken = randomUUID(); const mockedIdToken = await mockIdToken({}); const tokenSet: SessionTokenSet = { - accessToken: "access.token.jwt", + accessToken: mockedAccessToken, idToken: mockedIdToken, clientId: mockClientId, issuer: mockOpConfig().issuer, @@ -230,7 +235,7 @@ describe("Session static functions", () => { }) as typeof fetch; await session.fetch("https://some.resource"); // @ts-expect-error We know headers is initialized. - expect(headers.get("Authorization")).toBe(`DPoP ${mockedIdToken}`); + expect(headers.get("Authorization")).toBe(`DPoP ${mockedAccessToken}`); // @ts-expect-error We know headers is initialized. expect(headers.get("dpop")).not.toBeNull(); globalThis.fetch = globalFetch; diff --git a/packages/node/src/Session.ts b/packages/node/src/Session.ts index 5e79472e7e..185e6e9152 100644 --- a/packages/node/src/Session.ts +++ b/packages/node/src/Session.ts @@ -284,12 +284,12 @@ export class Session implements IHasSessionEventListener { if ( isExpired || webId === undefined || - sessionTokenSet.idToken === undefined + sessionTokenSet.accessToken === undefined ) { return session; } - const fetch = buildAuthenticatedFetch(sessionTokenSet.idToken, { + const fetch = buildAuthenticatedFetch(sessionTokenSet.accessToken, { dpopKey: sessionTokenSet.dpopKey, expiresIn: sessionTokenSet.expiresAt ? sessionTokenSet.expiresAt - Date.now()