Skip to content

Commit

Permalink
feat: session token authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpascal committed May 5, 2024
1 parent 4ff27e2 commit 8bfbbac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ const archivingApi = require('./archiving-api');
const environment = require('./environment');
const log = require('./log');
const url = require('url');
const { sessionTokenHeader } = require('./nools-utils');
const nools = require('./nools-utils');

const cache = new Map();

// const _request = (method) => (...args) => retry(() => rpn[method](...args), { retries: 5, randomize: false, factor: 1.5 });

// Helper function to create request headers with session token (if available)
const withCookieSession = (options) => {
return Object.assign({}, options, {
headers: Object.assign({}, options.headers || {}, {
Cookie: sessionTokenHeader(environment) || undefined
Cookie: nools.sessionTokenHeader(environment) || undefined
})
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ PouchDB.plugin(require('pouchdb-mapreduce'));

const ArchivingDB = require('./archiving-db');
const environment = require('./environment');
const { sessionTokenHeader } = require('./nools-utils');
const nools = require('./nools-utils');

module.exports = () => {
if (environment.isArchiveMode) {
return new ArchivingDB(environment.archiveDestination);
}
const headers = sessionTokenHeader(environment);
const headers = nools.sessionTokenHeader(environment);
return new PouchDB(environment.apiUrl, { ajax: { timeout: 60000, headers } });
};

1 change: 1 addition & 0 deletions test/api-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
const port = server.address().port;
const couchUrl = `http://admin:pass@localhost:${port}/medic`;
sinon.stub(environment, 'apiUrl').get(() => couchUrl);
sinon.stub(environment, 'sessionToken').get(() => undefined);
module.exports.couchUrl = couchUrl;
module.exports.gatewayRequests = [];
},
Expand Down

0 comments on commit 8bfbbac

Please sign in to comment.