ActiveResource HTTP basic auth with email address

As I’ve started to play around here and there with ActiveResource, I’ve noticed lots of complaints about how ActiveResource’s implementation of HTTP basic auth leaves a lot to be desired. Specifically with regard to its lack of support for email addresses as usernames. This won’t work:

class Expense < ActiveResource::Base
  self.site = "https://barry@bjhess.com:password@website.com"
end

Turns out it’s fairly simple to authorize via email address in ActiveResource. Just send the header:

class Expense < ActiveResource::Base
  self.site = "https://website.com"
  @headers  = { ‘Authorization’ => "Basic (#{Base64.encode64(’barry@bjhess.com:password’).strip})" }
end

Technorati Tags: , ,

Share if you like: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • StumbleUpon
  • del.icio.us
  • Technorati
  • Ma.gnolia
  • Reddit
  • DZone