authenticator
authenticator is a small Clojure library that can be used to easily implement a java.net.Authenticator.
Authenticators can be asked to provide username and password for network connections that require them.
Installation
authenticator artifacts are released on clojars.
Usage
(require '[authenticator.core :as auth])
(defn get-credentials
[options]
(println "options" options)
(when (= (:host options) "localhost")
["user" "password"]))
(auth/set-default-authenticator get-credentials)
(slurp "http://localhost/secret/")
The get-credentials function above is called with a single map as argument. It contains the following keys:
- :host
- hostname of the site or proxy requesting authentication, or nil if not available
- :port
- port number for the requested connection
- :prompt
- prompt string given by the requestor
- :protocol
- protocol for the requested connection
- :scheme
- scheme for the requested connection
- :site
- InetAddress of the site requesting authorization, or null if not available
- :url
- URL that resulted in this request for authentication
- :requestor-type
- :proxy for a Proxy or :server otherwise
The function should return a [username, password] pair to be used with the connection or nil if it can't supply credentials.
License
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.