clojurewerkz/spyglass — pull request #9 by ecmendenhall (2013-08-20 23:46:48+00:00)
Title: Add custom net.spy.memcached.auth.AuthDescriptor.

```
Fixes issue #6.

+ Fix SASL authentication errors for Heroku users.
+ Allow passing an optional auth-type argument to
spyglass.client/bin-connection.
+ Pull out net.spy.memcached.auth.AuthDescriptor
construction to spyglass.client/auth-descriptor
function. Passing :plain or :cram-md5 keywords
specifies an auth mechanism. (AuthDescriptors
initialized with AuthDescriptor/typical threw
authentication errors for users connecting to
Heroku's default memcached servers).
```

Six months later and I've learned enough Clojure/Java to figure this out. This should fix authentication errors for users connecting to the default Heroku memcache add-ons.

Memcachier (one of the Heroku memcache add-on services) suggests [using spymemcached version 2.8.9](https://www.memcachier.com/documentation#java) or earlier. A [spymemcached issue](https://code.google.com/p/spymemcached/issues/detail?id=272) suggests creating an `AuthDescriptor` configured for plain auth only. In combination, these two fixes solve my original issue.

To downgrade to spymemcached 2.8.9 for use with Heroku, add it as a `project.clj` dependency _and_ add an exclusion to the spyglass dependency. Also, make sure to include the `spy-memcached` maven repository:

```
(defproject my-great-project "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[clojurewerkz/spyglass "1.1.0-beta6-SNAPSHOT"
:exclusions [spy/spymemcached]]
[spy/spymemcached "2.8.9"]]
:repositories {"spy-memcached" {:url "http://files.couchbase.com/maven2/"}})
```
Then, add a `:plain` argument to any calls to `client/bin-connection` to use a custom AuthDescriptor configured for plain authentication, e.g.:

```
(spyglass.client/bin-connection memcache-server memcache-username memcache-password :plain)
```
If you need a connection configured with cram-md5 only, that's a keyword option, too. This is an optional arg—calling `bin-connection` without the extra keyword returns the original `AuthDescriptor/typical`.

I'm not sure how to write an automated test for this, but it doesn't break any existing ones. I've tested this fix successfully by hand with both default Heroku memcached services.