Posterous
Lon is using Posterous to post everything online. Shouldn't you?
N1609401482_6396_thumb
 

Kickass Pixels

building success pixel by pixel

« Back to blog

Simple authentication for Sinatra in Rails Metal

Using Sinatra:Base to build Rails Metal is a joy and really speeds up the process.

I needed to protect API access with simple authentication and after trying a few routes I found this technique:
 
before do
  if request.env['PATH_INFO'].include?('/api/cool_stuff')
    Rack::Auth::Basic.new(request, 'API Access') do |username, password|
      Account.authenticate(username, password)
    end
  end
end

The trick was keeping the authentication from triggering for requests not meant for this path.

Loading mentions Retweet
Posted July 7, 2009
 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     twitter