diff --git a/src/__tests__/paxfulapi_refresh_test.ts b/src/__tests__/paxfulapi_refresh_test.ts index a529418..d8eb708 100644 --- a/src/__tests__/paxfulapi_refresh_test.ts +++ b/src/__tests__/paxfulapi_refresh_test.ts @@ -30,9 +30,14 @@ describe("With the Paxful API SDK", function () { const GET_PROFILE_URL = "/oauth2/userinfo/"; it("Client credentials reset flow. Get profile", async () => { + const initialAccessToken = UUID(); + fetchMock.once({ url: /oauth2\/userinfo/, - method: "GET" + method: "GET", + headers: { + Authorization: 'Bearer ' + initialAccessToken + } }, { status: 401, body: "" @@ -56,15 +61,19 @@ describe("With the Paxful API SDK", function () { fetchMock.once({ name: 'correct_access_token', url: /oauth2\/userinfo/, - method: "GET" + method: "GET", + headers: { + Authorization: 'Bearer abc' + } }, { status: 200, body: JSON.stringify({ some: "lala" }) }); + credentialStorage.getCredentials.mockReturnValue({ ...{ - accessToken: UUID(), + accessToken: initialAccessToken, refreshToken: UUID(), }, expiresAt: new Date() diff --git a/src/commands/RefreshIfNeeded.ts b/src/commands/RefreshIfNeeded.ts index 3f190b9..dfc9dd2 100644 --- a/src/commands/RefreshIfNeeded.ts +++ b/src/commands/RefreshIfNeeded.ts @@ -59,7 +59,7 @@ const createRefreshRequest = async (request: Request, config: ApiConfiguration, credentialStorage.saveCredentials(credentials); - request.headers["Authorization"] = `Bearer ${credentials.accessToken}`; + request.headers.set("Authorization", `Bearer ${credentials.accessToken}`) return Promise.resolve(request); }