Last active
December 9, 2015 19:17
-
-
Save select/20c8aa05b519bb59ace8 to your computer and use it in GitHub Desktop.
Tumblr OAuth for web2py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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