2nd pass on oauth, making more generic
This commit is contained in:
parent
2eaf09dc78
commit
838eb3cb06
2 changed files with 27 additions and 37 deletions
|
@ -5,38 +5,28 @@ from ..models import BaseUser
|
|||
|
||||
oauth = OAuth()
|
||||
|
||||
users = {}
|
||||
|
||||
class OAuthUser(BaseUser):
|
||||
# OAuth remote app
|
||||
remote_app = None
|
||||
|
||||
|
||||
class TwitterUser(OAuthUser):
|
||||
|
||||
def __init__(self, id_, username, email=None):
|
||||
self.id = id_
|
||||
self.username = username
|
||||
self.email = email
|
||||
|
||||
@classmethod
|
||||
def app(cls):
|
||||
if cls.remote_app:
|
||||
return cls.remote_app
|
||||
|
||||
cls.remote_app = oauth.remote_app(
|
||||
'twitter',
|
||||
providers = {
|
||||
'twitter': {
|
||||
'oauth': dict(
|
||||
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
|
||||
authorize_url='https://api.twitter.com/oauth/authenticate')
|
||||
}
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def load_user(*args, **kwargs):
|
||||
return TwitterUser(args[0])
|
||||
|
||||
class User(BaseUser):
|
||||
|
||||
@classmethod
|
||||
def get_app(cls, provider):
|
||||
return oauth.remote_app(provider,
|
||||
consumer_key=config.OAUTH.get(provider, {}).get('key'),
|
||||
consumer_secret=config.OAUTH.get(provider, {}).get('secret'),
|
||||
**providers[provider]['oauth'])
|
||||
|
||||
@staticmethod
|
||||
def login_form():
|
||||
return render_template('auth/oauth/twitter.html')
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue