1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 package couchdb 14 15 import ( 16 "github.com/go-kivik/kivik/v4" 17 "github.com/go-kivik/kivik/v4/couchdb/chttp" 18 ) 19 20 // BasicAuth provides support for HTTP Basic authentication. Pass this option 21 // to [github.com/go-kivik/kivik/v4.New] to use Basic Authentication. 22 func BasicAuth(username, password string) kivik.Option { 23 return chttp.BasicAuth(username, password) 24 } 25 26 // CookieAuth provides CouchDB [Cookie auth]. Cookie Auth is the default 27 // authentication method if credentials are included in the connection URL 28 // passed to [github.com/go-kivik/kivik/v4.New]. You may also pass this option 29 // as an argument to the same function, if you need to provide your auth 30 // credentials outside of the URL. 31 // 32 // [Cookie auth]: http://docs.couchdb.org/en/2.0.0/api/server/authn.html#cookie-authentication 33 func CookieAuth(username, password string) kivik.Option { 34 return chttp.CookieAuth(username, password) 35 } 36 37 // JWTAuth provides support for CouchDB JWT-based authentication. Kivik does 38 // no validation on the JWT token; it is passed verbatim to the server. 39 // 40 // See https://docs.couchdb.org/en/latest/api/server/authn.html#jwt-authentication 41 func JWTAuth(token string) kivik.Option { 42 return chttp.JWTAuth(token) 43 } 44 45 // ProxyAuth provides support for CouchDB's [proxy authentication]. Pass this 46 // option to [github.com/go-kivik/kivik/v4.New] to use proxy authentication. 47 // 48 // The `secret` argument represents the [couch_httpd_auth/secret] value 49 // configured on the CouchDB server. 50 // 51 // If `secret` is the empty string, the X-Auth-CouchDB-Token header will not be 52 // set, to support disabling the [proxy_use_secret] server setting. 53 // 54 // The optional `headers` map may be passed to use non-standard header names. 55 // For instance, to use `X-User` in place of the `X-Auth-CouchDB-Username` 56 // header, pass a value of {"X-Auth-CouchDB-UserName": "X-User"}. 57 // The relevant headers are X-Auth-CouchDB-UserName, X-Auth-CouchDB-Roles, and 58 // X-Auth-CouchDB-Token. 59 // 60 // [proxy authentication]: https://docs.couchdb.org/en/stable/api/server/authn.html?highlight=proxy%20auth#proxy-authentication 61 // [couch_httpd_auth/secret]: https://docs.couchdb.org/en/stable/config/auth.html#couch_httpd_auth/secret 62 // [proxy_use_secret]: https://docs.couchdb.org/en/stable/config/auth.html#couch_httpd_auth/proxy_use_secret 63 func ProxyAuth(user, secret string, roles []string, headers ...map[string]string) kivik.Option { 64 return chttp.ProxyAuth(user, secret, roles, headers...) 65 } 66