Skip to content

Instantly share code, notes, and snippets.

@select
Last active December 9, 2015 19:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save select/20c8aa05b519bb59ace8 to your computer and use it in GitHub Desktop.
Save select/20c8aa05b519bb59ace8 to your computer and use it in GitHub Desktop.
Tumblr OAuth for web2py
from gluon.contrib.login_methods.oauth10a_account import OAuthAccount
import pytumblr
class TumblrOAuth(OAuthAccount):
"""OAuth for Tumblr"""
# Define oauth application id and secret.
consumer_key = 'XXX'
consumer_secret = 'XXX'
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'
def __init__(self, g):
OAuthAccount.__init__(self, g,
self.consumer_key,
self.consumer_secret,
self.authorize_url,
self.request_token_url,
self.access_token_url)
def get_user(self):
if not self.accessToken():
return None
client = pytumblr.TumblrRestClient(
self.consumer_key,
self.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(g=globals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment