Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: fce329ebb3
Fetching contributors…

Cannot retrieve contributors at this time

103 lines (70 sloc) 3.684 kB
FlickrApp
FlickrApp is a simple base class to use with Google App Engine (GAE)
packages that allows you to use Flickr as a Single Sign On (SSO)
provider and validation service. As an extra bonus you get a Flickr
API Auth token in the process!
Currently this class is designed (and tested) to work with the plain
vanilla GAE/Django development environment. The next step is to ensure
that is works with the AppDrop GAE/EC2 container.
CLASS METHODS
__init__(self, api_key, api_secret)
Create a new FlickrApp object.
Remember, this class is not meant to be used on it's own. Rather
it is a base class that you subclass in your own application. For
example:
class MyFlickrApp (FlickrApp) :
def init (self) :
api_key = "this part is left to you"
api_secret = "to squirt in to your application"
FlickrApp.__init__(self, api_key, api_secret)
OBJECT METHODS YOU SHOULD CARE ABOUT
check_logged_in(self, min_perms=None)
Check to see if the current user is logged in. If not, force
them to re-authenticate your application via the Flickr API
Auth flow.
Logged in is defined as having valid 'ffo' and 'fft' cookies.
'ffo' cookies are constantly renewed for 30 days with each page
view and map the current user to a user in the FlickrUser database.
If the cookie is not present or does not validate this method
returns False.
'fft' cookies last the duration of the browser session and are
used to ensure that the user has a token with a minimum permissions
set. This is done by calling the flickr.auth.checkToken method. If
the token does not match this method returns False.
If both cookies validate, the object's 'user' key will be set and
the method will return True.
For example:
class MyHandler (FlickrApp) :
# Assume __init__ here...
def get (self) :
min_perms = 'read'
if not self.check_logged_in(min_perms) :
self.do_flickr_auth(min_perms)
return
self.response.out.write("Hi there %s" % self.user.username)
do_flickr_auth(self, min_perms=None)
This method will generate and redirect the user to the Flickr
API Auth endpoint where the user will be prompted to approve
your request for a Flickr token (with 'min_perms' permissions).
do_token_dance(self, perms=None)
This is the method you should call from your 'auth' handler; that
is the URL that you tell the Flickr API Auth flow to redirect to
once a user has authed your application (in magic Flickr land).
It will check for a 'frob' parameter and then call the Flickr API
and exchange it for a valid Flickr Auth token.
If something goes wrong it will return False, otherwise it will
redirect the user to your application's root URL (where presumably
you are calling 'checked_logged_in').
For example:
class TokenFrobHandler (FlickrApp) :
# Assume __init__ here
def get (self):
try :
self.do_token_dance() :
except Exception, e :
self.response.out.write("OH NOES! SOMETHING WENT WRONG!")
EVERYTHING ELSE
Everything is a bit up in the air still. The documentation will be updated when
the dust settles.
REQUIREMENTS
Just the Google AppEngine (GAE) package itself.
Jump to Line
Something went wrong with that request. Please try again.