views:

53

answers:

2

I want to have RSS feeds in my Django application, which should be viewable only by a logged-in user. I want to allow users to add these RSS feeds to all aggregators, so I would need something which would work like this: supply the feed URL with a token, for example: http://example.com/feed/rss&token=AeYQtFjQfjU5m so that token will cause the feed to be seen as if the user would be logged in.

Is there some library in Django which would provide such a functionality?

+2  A: 

You could generate the token when creating a user for the first time. This way you can add the token to the feed when a user is logged in. Later when a RSS feed reader comes by your site for the user, you just load the user information for the user with that token.

Peter Stuifzand
that is basically security by obscurity, but at the same time it's the best possible solution, since RSS aggregators tend to have zero support for authentication
Jiaaro
I didn't describe the way that you could generate the token. I would use some kind of randomly generated token, because it's easier to regenerate if it's compromised. Your solution would work to.
Peter Stuifzand
+1  A: 

Try making a hash of some unique property of the user... something like

md5("%s!%s" % (SECRET_KEY, user.username)).hexdigest()

PS - I didn't test this code but you get the idea

Jiaaro
OK, thanks. Just two notes: if I "import md5" it results in TypeError: 'module' object is not callableTook me a while to find out I need md5.md5("%s!%s" % (SECRET_KEY, user.username)).hexdigest()But then found out that this is depreceated, and since Python 2.5 one should use: hashlib.md5("%s!%s" % (SECRET_KEY, user.username)).hexdigest()or even: hashlib.sha512("%s!%s" % (SECRET_KEY, user.username)).hexdigest()
miernik
yeah that should start with `from hashlib import md5` =D
Jiaaro