Skip to content

Commit

Permalink
Merge branch 'main' into fix/forms-1445-ext-api-drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
usingtechnology authored Aug 19, 2024
2 parents c437205 + cdf4036 commit f516e86
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
46 changes: 23 additions & 23 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"@json2csv/transforms": "^6.1.3",
"api-problem": "^9.0.2",
"aws-sdk": "^2.1376.0",
"axios": "^0.28.1",
"axios-oauth-client": "^1.5.0",
"axios": "^1.7.4",
"axios-oauth-client": "^2.2.0",
"axios-token-interceptor": "^0.2.0",
"bytes": "^3.1.2",
"compression": "^1.7.4",
Expand Down
26 changes: 17 additions & 9 deletions app/src/components/clientConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ const tokenProvider = require('axios-token-interceptor');

const log = require('./log')(module.filename);

// axios-oauth-client removed the "interceptor" in v2.2.0. Replicate it here.

const getMaxAge = (res) => {
return res.expires_in * 1e3;
};

const headerFormatter = (res) => {
return 'Bearer ' + res.access_token;
};

const interceptor = (tokenProvider, authenticate) => {
const getToken = tokenProvider.tokenCache(authenticate, { getMaxAge });

return tokenProvider({ getToken, headerFormatter });
};

class ClientConnection {
constructor({ tokenUrl, clientId, clientSecret }) {
log.verbose(`Constructed with ${tokenUrl}, ${clientId}, clientSecret`, { function: 'constructor' });
Expand All @@ -19,15 +35,7 @@ class ClientConnection {
// Wraps axios-token-interceptor with oauth-specific configuration,
// fetches the token using the desired claim method, and caches
// until the token expires
oauth.interceptor(
tokenProvider,
oauth.client(axios.create(), {
url: this.tokenUrl,
grant_type: 'client_credentials',
client_id: clientId,
client_secret: clientSecret,
})
)
interceptor(tokenProvider, oauth.clientCredentials(axios.create(), tokenUrl, clientId, clientSecret))
);
}
}
Expand Down

0 comments on commit f516e86

Please sign in to comment.