{"id":13555071,"url":"https://github.com/tyler-johnson/couchdb-auth-proxy","last_synced_at":"2025-04-28T05:34:57.810Z","repository":{"id":137744077,"uuid":"64867131","full_name":"tyler-johnson/couchdb-auth-proxy","owner":"tyler-johnson","description":"An HTTP reverse proxy server for easy Couchdb proxy authentication","archived":false,"fork":false,"pushed_at":"2018-03-21T12:50:48.000Z","size":16,"stargazers_count":28,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-04T03:32:45.097Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tyler-johnson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-08-03T17:54:12.000Z","updated_at":"2024-02-23T15:41:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9b5e3f0-e9e3-46c5-a265-7b7f84a9b70a","html_url":"https://github.com/tyler-johnson/couchdb-auth-proxy","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler-johnson%2Fcouchdb-auth-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler-johnson%2Fcouchdb-auth-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler-johnson%2Fcouchdb-auth-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler-johnson%2Fcouchdb-auth-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tyler-johnson","download_url":"https://codeload.github.com/tyler-johnson/couchdb-auth-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224099463,"owners_count":17255562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:03:01.007Z","updated_at":"2024-11-11T11:49:49.821Z","avatar_url":"https://github.com/tyler-johnson.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"# CouchDB Auth Proxy\n\n[![npm](https://img.shields.io/npm/v/couchdb-auth-proxy.svg)](https://www.npmjs.com/package/couchdb-auth-proxy) [![Build Status](https://travis-ci.org/tyler-johnson/couchdb-auth-proxy.svg?branch=master)](https://travis-ci.org/tyler-johnson/couchdb-auth-proxy)\n\nA Node.js HTTP reverse proxy library for quick and dirty CouchDB proxy authentication.\n\n## Install\n\nInstall from NPM\n\n```bash\nnpm install couchdb-auth-proxy -S\n```\n\nAnd import into your project\n\n```js\nimport couchdbProxy from \"couchdb-auth-proxy\";\n```\n\n```js\nconst couchdbProxy = require(\"couchdb-auth-proxy\");\n```\n\n## Usage\n\n\u003e Note: Ensure proxy authentication is enabled on your CouchDB server. This is as simple as adding `{couch_httpd_auth, proxy_authentication_handler}` to the list of active authentication handlers in your configuration. See the [CouchDB Docs](http://docs.couchdb.org/en/1.6.1/api/server/authn.html#proxy-authentication) for more info.\n\nThis library generates an HTTP server request function from two arguments: a user context method and some options. This method will work with Express/Connect apps as well as the plain Node.js HTTP server.\n\nHere is an example proxy that authenticates every request as a super admin:\n\n```js\nconst server = http.createServer(couchdbProxy(function(req) {\n  // admin party!\n  return {\n    name: null,\n    roles: [ \"_admin\" ]\n  };\n}));\n```\n\nIn CouchDB, users are represented with a user context object. These are objects with `name` and `roles` fields. Usually this information comes from a document in the `_users` database, however we can also generate it from other means.\n\nYour proxy can complete asynchronous tasks, great for authenticating against other databases or services. You can return a promise, or provide a third argument for a callback.\n\n```js\nconst server = http.createServer(couchdbProxy(function(req, res, next) {\n  const token = req.get(\"Authorization\");\n\n  db.authenticateToken(token, (err, user) =\u003e {\n    if (err) return next(err);\n\n    next(null, {\n      name: user.name,\n      roles: []\n    });\n  });\n}));\n```\n\n## API\n\n#### `couchdbProxy( userCtxFn [, options ] ) → Middleware`\n\n- `userCtxFn` (Function, *required*) - Method called on every request, with the request `req` and response `res` as arguments. This method should return a plain object with `name` and `roles` fields, representing the authenticated user. To run an async task, return a promise or pass a third argument `next` for a callback.\n- `options` (Object) - Options to configure the proxy.\n  - `options.target` (String) - The URL of the CouchDB server to proxy to. This server must have [proxy authentication enabled](http://docs.couchdb.org/en/1.6.1/api/server/authn.html#proxy-authentication). Defaults to `http://localhost:5984`.\n  - `options.secret` (String) - The [CouchDB secret](http://docs.couchdb.org/en/1.6.1/config/auth.html#couch_httpd_auth/secret) used to sign proxy tokens and cookies. This is only required if `couch_httpd_auth/proxy_use_secret` is enabled on CouchDB (which is recommended).\n  - `options.via` (String) - The name of the proxy to add to the `Via` header. This is so consumers of the HTTP API can tell that the request was directed through a proxy. This is optional and the `Via` header will be excluded when not provided.\n  - `options.headerFields` (Object) - A map of custom header fields to use for the proxy. This should match what is declared in CouchDB `couch_httpd_auth` configuration, under `x_auth_roles`, `x_auth_token`, and `x_auth_username`. This is the default map:\n  ```json\n  {\n    \"username\": \"X-Auth-CouchDB-UserName\",\n    \"roles\": \"X-Auth-CouchDB-Roles\",\n    \"token\": \"X-Auth-CouchDB-Token\"\n  }\n  ```\n  - `options.info` (Object) - Some JSON serializable value that will be injected into the CouchDB's root info document response.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler-johnson%2Fcouchdb-auth-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyler-johnson%2Fcouchdb-auth-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler-johnson%2Fcouchdb-auth-proxy/lists"}