ldap first pass
This commit is contained in:
parent
3c2f4a0445
commit
2eaf09dc78
13 changed files with 148 additions and 25 deletions
|
@ -8,25 +8,31 @@ oauth = OAuth()
|
|||
|
||||
class OAuthUser(BaseUser):
|
||||
# OAuth remote app
|
||||
app = None
|
||||
remote_app = None
|
||||
|
||||
|
||||
class TwitterUser(OAuthUser):
|
||||
|
||||
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.TWITTER_KEY,
|
||||
consumer_secret=config.TWITTER_SECRET)
|
||||
|
||||
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',
|
||||
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
|
||||
|
||||
@staticmethod
|
||||
def load_user(*args, **kwargs):
|
||||
return TwitterUser(args[0])
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
from flask import Blueprint, url_for, request, flash, redirect
|
||||
from flask import Blueprint, url_for, request, flash, redirect, session
|
||||
from .models import TwitterUser
|
||||
|
||||
blueprint = Blueprint('auth.oauth', __name__)
|
||||
|
||||
|
||||
def oauth_failed(next_url):
|
||||
flash(u'You denied the request to sign in.')
|
||||
flash('You denied the request to sign in.')
|
||||
return redirect(next_url)
|
||||
|
||||
@blueprint.route("/login/twitter")
|
||||
def login_twitter():
|
||||
return TwitterUser.app.authorize(callback=url_for('twitter_callback',
|
||||
next=request.args.get('next') or request.referrer or None))
|
||||
return TwitterUser.app().authorize(callback=url_for('twitter_callback',
|
||||
next=request.args.get('next') or request.referrer or None))
|
||||
|
||||
@blueprint.route('/login/twitter/callback')
|
||||
def twitter_callback():
|
||||
next_url = request.args.get('next') or url_for('index')
|
||||
resp = TwitterUser.app.authorized_response()
|
||||
resp = TwitterUser.app().authorized_response()
|
||||
if resp is None:
|
||||
return oauth_failed(next_url)
|
||||
|
||||
|
@ -27,4 +27,4 @@ def twitter_callback():
|
|||
session['twitter_user'] = resp['screen_name']
|
||||
|
||||
flash('You were signed in as %s' % resp['screen_name'])
|
||||
return redirect(next_url)
|
||||
return redirect(next_url)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue