I needed HTTP basic authentication for a Sinatra app running as a Rails Metal. I have two apps, one running Clearance and another running Authlogic.

Using the info from my previous post, I wrote a small Sinatra plugin that works with both Clearance and Authlogic.

Throw the file above in lib/sinatra_authentication.rb. Then, your metal, app/metals/api.rb would look something like this:

Authlogic doesn’t have an authenticate method, so I added this to app/models/user.rb:

Hope it helps someone else.