views:

251

answers:

4

Creating RSS feed in rails is easy. I need a simple way to password protect the RSS feed. I am thinking http basic authentication.

I googled but could not find any article about creating password protected RSS.

+2  A: 

Just use whatever auth system you use on your regular controllers. If the user is logged, and session is alive he will be able to download the feed.

knoopx
A: 

Like knoopx said, If you use an authentication system like authlogic you should be able to specify the authentication type in the controller. You can then specify http basic authenication. Then you can, if you choose, include the authentication in the URL for the RSS Feed.

e.g:

http://username:[email protected]/rss

(sorry to break the URI up like that, but I don't have enough reputation points to post multiple links :( )

Jordan Brock
...However, the password should never be stored in plaintext in your database anyway, and making so that if someone clicks a link their password is shown to absolutely anyone who might be with them is just unsafe.
Matchu
Matchu, I agree that the password should never be stored in plain text in the password. I was just putting it in there as an example of what can be achieved. Obviously, the best scenario is that the RSS client has the authentication mechanism built in.
Jordan Brock
+1  A: 

I have this in my ApplicationController

def xml_authorize
  if request.format == Mime::XML
    authenticate_or_request_with_http_basic do |username, password|
      username == 'foo' && password == 'bar'
    end
  end
end

Then I just apply a before_filter :xml_authorize to the actions that I want to password protect for XML requests only, but still want to serve normally with html.


Here's where I got the inspiration from.

Blaine LaFreniere
+1  A: 

How is HTTP authentication any different on RSS feeds than other controller actions? (This is not necessarily a rhetorical question - is it actually different?)

Have you tried just using the Rails HTTP Basic Authentication methods?

Matchu