This is how you login to your web2py app with Tumblr
Register a Tumblr app (you will of course need a Tumblr account)
https://www.tumblr.com/oauth/registerand configure later at
https://www.tumblr.com/settings/appsget the consumer key and secret
install the oauth2 lib (on ubuntu)
sudo apt-get install python-oauth2
or on any other platform
pip install --user python-oauth2
download the pytumblr lib from (Download ZIP in right menu)
https://github.com/tumblr/pytumblrextract only the pytumblr folder to yourapp/modules
edit yourapp/modules/pytumblr/__init__.py and add dot "." in front of the helpers and request import like this
from .helpers import validate_params, validate_blogname
from .request import TumblrRequest
add the following code to your db.py
consumer_key = 'XXXXXXX'
consumer_secret = 'XXXXXX'
request_token_url = 'http://www.tumblr.com/oauth/request_token'
authorize_url = 'http://www.tumblr.com/oauth/authorize'
access_token_url = 'http://www.tumblr.com/oauth/access_token'
from gluon.contrib.login_methods.oauth10a_account import OAuthAccount
import pytumblr
class TumblrOAuth(OAuthAccount):
"""OAuth for Tumblr"""
def get_user(self):
if not self.accessToken():
return None
client = pytumblr.TumblrRestClient(
consumer_key,
consumer_secret,
self.accessToken().key,
self.accessToken().secret,
)
info = client.info()
if info and ('user' in info):
return dict(
first_name=info['user']['name'],
registration_id='tumblr:%s' % info['user']['name'],
)
auth.settings.login_form = TumblrOAuth(globals(), consumer_key, consumer_secret, authorize_url, request_token_url, access_token_url)
Replace the consumer key and secret with yours! Tumblr does not provide first or last name or an id thats why only the crude info in the return. I do not really need to create proper users so this is enough for me, you can improve on that. Also this approach will let you log in only with Tumblr, you will have to figure our the rest, this is only a basic tutorial.
Did I miss anything? Did you like that? Write a comment!