2015-10-14 06:52:30 +03:00
|
|
|
from flask import render_template
|
|
|
|
from flask_oauthlib.client import OAuth
|
|
|
|
from realms import config
|
|
|
|
from ..models import BaseUser
|
|
|
|
|
|
|
|
oauth = OAuth()
|
|
|
|
|
|
|
|
|
|
|
|
class OAuthUser(BaseUser):
|
|
|
|
# OAuth remote app
|
2015-10-15 01:36:22 +03:00
|
|
|
remote_app = None
|
2015-10-14 06:52:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
class TwitterUser(OAuthUser):
|
|
|
|
|
|
|
|
def __init__(self, id_, username, email=None):
|
|
|
|
self.id = id_
|
|
|
|
self.username = username
|
|
|
|
self.email = email
|
|
|
|
|
2015-10-15 01:36:22 +03:00
|
|
|
@classmethod
|
|
|
|
def app(cls):
|
|
|
|
if cls.remote_app:
|
|
|
|
return cls.remote_app
|
|
|
|
|
|
|
|
cls.remote_app = oauth.remote_app(
|
|
|
|
'twitter',
|
|
|
|
base_url='https://api.twitter.com/1/',
|
|
|
|
request_token_url='https://api.twitter.com/oauth/request_token',
|
|
|
|
access_token_url='https://api.twitter.com/oauth/access_token',
|
|
|
|
authorize_url='https://api.twitter.com/oauth/authenticate',
|
|
|
|
consumer_key=config.OAUTH['twitter']['key'],
|
|
|
|
consumer_secret=config.OAUTH['twitter']['secret'])
|
|
|
|
return cls.remote_app
|
|
|
|
|
2015-10-14 06:52:30 +03:00
|
|
|
@staticmethod
|
|
|
|
def load_user(*args, **kwargs):
|
|
|
|
return TwitterUser(args[0])
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def login_form():
|
|
|
|
return render_template('auth/oauth/twitter.html')
|