Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Commit

Permalink
Added support for oauth authentication for couchdb
Browse files Browse the repository at this point in the history
This is used when google auth is used for authentication.
  • Loading branch information
jkleinsc committed Mar 16, 2016
1 parent 796bc87 commit e371b2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions forward.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
var onHeaders = require('on-headers');
var request = require('request');

module.exports = function(host, config) {
module.exports = function(host, config, useOauth) {
return function(req, res) {
var forwardURL = host + req.url;
var requestOptions = {
url: forwardURL
};
var reqMethod = req.method.toLowerCase();
if (reqMethod == 'delete') {
reqMethod = 'del';
}
if (config.useGoogleAuth && useOauth) {
if (req.get('x-oauth-consumer-key')) {
requestOptions.oauth = {
consumer_key: req.get('x-oauth-consumer-key'),
consumer_secret: req.get('x-oauth-consumer-secret'),
token: req.get('x-oauth-token'),
token_secret: req.get('x-oauth-token-secret')
};
}
}

if (config.emberCLI) {
// Ember CLI uses compression (https://www.npmjs.com/package/compression) which
// causes issues when proxying requests, so turn off compression for proxied requests.
onHeaders(res, function() {
res.header('Cache-Control','no-transform');
});
}
req.pipe(request[reqMethod](forwardURL).on('error', function(err) {
req.pipe(request[reqMethod](requestOptions).on('error', function(err) {
console.log('Got error forwarding: ', err);
})).pipe(res);
};
Expand Down
2 changes: 1 addition & 1 deletion routes/10-couchproxy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var forward = require('../forward.js');

module.exports = function(app, config) {
app.use('/db/', forward(config.couchDbURL, config));
app.use('/db/', forward(config.couchDbURL, config, true));
};

0 comments on commit e371b2a

Please sign in to comment.