Ejemplo n.º 1
0

@app.route('/')
def redirect_to_admin():
    return redirect('/admin')


@app.errorhandler(401)
def login_require(e):
    """HTTP<401>."""
    return redirect("%s?next=%s" % (url_for('login'), request.path))


# Oauth
if app.config['GITHUB']:
    oauth = oauth.OAuth()
    github = oauth.remote_app('github', **app.config['GITHUB'])

    admin.add_path_security('/',
                            lambda: 'github_token' in session,
                            http_code=401)

    @app.route('/login')
    def login():
        """Signs in via github.
        """
        return github.authorize(callback=url_for('github_authorized',
                                                 next=request.args.get('next')
                                                 or request.referrer or None,
                                                 _external=True))
Ejemplo n.º 2
0
        return user_db

    return create_user_db(
        auth_id,
        re.sub(r'_+|-+|\.+', ' ',
               google_user.email().split('@')[0]).title(),
        google_user.email(),
        google_user.email(),
        admin=users.is_current_user_admin(),
    )


###############################################################################
# Twitter
###############################################################################
twitter_oauth = oauth.OAuth()

twitter = twitter_oauth.remote_app(
    'twitter',
    base_url='https://api.twitter.com/1.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/authorize',
    consumer_key=config.CONFIG_DB.twitter_consumer_key,
    consumer_secret=config.CONFIG_DB.twitter_consumer_secret,
)


@app.route('/_s/callback/twitter/oauth-authorized/')
@twitter.authorized_handler
def twitter_authorized(resp):
Ejemplo n.º 3
0
from __future__ import absolute_import

import os
import datetime
import flask
from gevent import pool
from flask.ext import oauth
from flask.ext import login

import twitter as twitter_api

from sirius.models import user as user_model
from sirius.models.db import db

blueprint = flask.Blueprint('twitter_oauth', __name__)
oauth_app = oauth.OAuth()

# TODO move the consumer_key/secret to flask configuration. The
# current key is a test app that redirects to 127.0.0.1:8000.
twitter = oauth_app.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=os.environ.get('TWITTER_CONSUMER_KEY',
                                'DdrpQ1uqKuQouwbCsC6OMA4oF'),
    consumer_secret=os.environ.get(
        'TWITTER_CONSUMER_SECRET',
        'S8XGuhptJ8QIJVmSuIk7k8wv3ULUfMiCh9x1b19PmKSsBh1VDM'),
)