Log in

tipfy.ext.auth.friendfeed

This extension allows you to authenticate and make FriendFeed API requests on behalf of users on App Engine.

You can use it to provide FriendFeed login for a site or to fetch FriendFeed feeds.

Try our FriendFeed auth demo (source here).

FriendFeed authentication

To authenticate with FriendFeed, register your application with FriendFeed at http://friendfeed.com/api/applications. Then copy your Consumer Key and Consumer Secret to config.py:

config['tipfy.ext.auth.friendfeed'] = {
    'consumer_key':    'XXXXXXXXXXXXXXX',
    'consumer_secret': 'XXXXXXXXXXXXXXX',
}

When your application is set up, you can use the FriendFeedMixin to authenticate the user with FriendFeed and get access to their stream. You must use the mixin on the handler for the URL you registered as your application's Callback URL. For example:

from tipfy import RequestHandler, abort
from tipfy.ext.auth.friendfeed import FriendFeedMixin
from tipfy.ext.session import CookieMixin, SessionMiddleware

class FriendFeedHandler(RequestHandler, CookieMixin, FriendFeedMixin):
    middleware = [SessionMiddleware]
    
    def get(self):
        if self.request.args.get('oauth_token', None):
            return self.get_authenticated_user(self._on_auth)

        return self.authorize_redirect()

    def _on_auth(self, user):
        if not user:
            abort(403)

        # Set the user in the session.
        # ...

CookieMixin and SessionMiddleware are needed because the handler sets a temporary cookie during authentication.

The user object returned by get_authenticated_user() includes the attributes 'username', 'name', and 'description' in addition to 'access_token'. You should save the access token with the user; it is required to make requests on behalf of the user later with friendfeed_request().

FriendFeed API requests

You can make FriendFeed API requests using friendfeed_request().

If the request is a POST, post_args should be provided. Query string arguments should be given as keyword arguments.

All the FriendFeed methods are documented at http://friendfeed.com/api/documentation.

Many methods require an OAuth access token which you can obtain through authorize_redirect() and get_authenticated_user(). The user returned through that process includes an 'access_token' attribute that can be used to make authenticated requests via this method. Example usage:

from tipfy import RequestHandler, Response
from tipfy.ext.auth.friendfeed import FriendFeedMixin
from tipfy.ext.session import CookieMixin, SessionMiddleware

class MainHandler(RequestHandler, FriendFeedMixin):
    middleware = [SessionMiddleware]

    def get(self):
        return self.friendfeed_request('/entry',
            post_args={'body': 'Testing Tornado Web Server'},
            access_token=self.current_user['access_token'],
            callback=self._on_post)

    def _on_post(self, new_entry):
        if not new_entry:
            # Call failed; perhaps missing permission?
            return self.authorize_redirect()

        return Response('Posted a message!')

Extension Reference


Powered by Moe. Yeah, the name is Moe. Powered by Google App Engine