Skip to content

Commit

Permalink
DP-1147 Fixed case when credentials in request are not updated after …
Browse files Browse the repository at this point in the history
…token refresh (#28)


Co-authored-by: Aleksandr Ader <[email protected]>
  • Loading branch information
a-ader and Aleksandr Ader authored Jan 27, 2022
1 parent b09717b commit aa0aceb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/__tests__/paxfulapi_refresh_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/RefreshIfNeeded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit aa0aceb

Please sign in to comment.