README.md

# couchdb_auth

Authentication helpers for the Apache CouchDB REST API, written in Elixir.

* Tested with:
  - Elixir 1.18.x / Erlang OTP 27
  - CouchDB 3.x

# Overview

Apache CouchDB REST API client for Elixir.

Small, focused API surface that builds pre-configured `Tesla.Client`s for the
main CouchDB interfaces.

### Features

* HTTP REST client
* HTTP Authentication:
  * Basic Auth
  * Cookie Auth
  * OAuth 1.0a
  * Bearer / JWT tokens
  * Proxy authentication headers
* Cluster/admin helpers for `_nodes` endpoints
* Local document helpers for `_local/<doc_id>`

## Installation

Add to mix.exs

```elixir
  def deps do
    [{:couchdb_auth, "~> 0.2.3"}]
  end
```

## Usage

Set required parameters in `config/*.exs` or via environment variables using the
`COUCHDB_` prefix (for example `COUCHDB_PROTOCOL`, `COUCHDB_HOSTNAME`, ...).

To send authorized requests to the database server (default port 5984):

`CouchDB.client() |> CouchDB.get("/_session")`

To send requests to the backend interface (default port 5986):

CouchDB.client(:backend) |> CouchDB.get("/_session")

Cluster-aware endpoints can be accessed via the admin interface, which
automatically prefixes `/_nodes/<node>` when clustering is enabled:

```elixir
CouchDB.admin_get("/_config")
```

JWT/Bearer tokens and proxy authentication are configured through the
application environment (or `COUCHDB_*` environment variables) by setting
`auth_type` to `:bearer` or `:proxy` respectively.

Accessing per-node local documents uses the `CouchDB.LocalDocs` helpers:

```elixir
CouchDB.LocalDocs.get("cache")
CouchDB.LocalDocs.put("cache", %{rev: "1-abc"})
```

About configuring OAuth, you can read this:

https://develixir.blogspot.com/2017/06/configuring-oauth-10-authentication.html