def test_authorization(self, auth_url, post): def assert_params(*args, **kwargs): data = kwargs.pop('data') assert data['client_id'] == '123' assert data['client_secret'] == 'SEKRET' assert data['code'] == 'KODE' response = Mock() response.content = b'access_token=asdf&token_type=bearer' return response post.side_effect = assert_params auth_url.__get__ = Mock(return_value='http://localhost/oauth/') app = Flask(__name__) app.config['GITHUB_CLIENT_ID'] = '123' app.config['GITHUB_CLIENT_SECRET'] = 'SEKRET' app.config['GITHUB_CALLBACK_URL'] = 'http://localhost/github-callback' github = GitHub(app) @app.route('/login') def login(): return github.authorize() @app.route('/github-callback') @github.authorized_handler def authorized(token): access_token.append(token) return '' # Mimics GitHub authorization URL # http://developer.github.com/v3/oauth/#web-application-flow @app.route('/oauth/authorize') def handle_auth(): called_auth.append(1) assert request.args['client_id'] == '123' assert request.args['redirect_uri'] == 'http://localhost/github-callback' return redirect(request.args['redirect_uri'] + '?code=KODE') access_token = [] called_auth = [] client = app.test_client() client.get('/login', follow_redirects=True) assert called_auth assert access_token == ['asdf']
from flask_migrate import Migrate from flask.ext.bcrypt import Bcrypt from flask.ext.admin.base import MenuLink from wtforms.fields import TextAreaField from flask.ext.github import GitHub from config import GITHUB_ADMIN, TIMELINE_URL, ASANA_CODE, ASANA_PROJECT_ID from sqlalchemy.sql import and_ import json import datetime, asana import pandas as pd app = Flask(__name__) app.config.from_pyfile('config.py') bcrypt = Bcrypt(app) # setup github-flask github = GitHub(app) #ends session so there's no mysql timeout @app.teardown_appcontext def shutdown_session(exception=None): db.session.remove() class MyAdminIndexView(AdminIndexView): @expose('/') def index(self): try: current_user.is_admin == True return self.render('admin/index.html') except:
rcpart.config['GITHUB_CLIENT_ID'] = os.environ['GITHUB_CLIENT_ID'] rcpart.config['GITHUB_CLIENT_SECRET'] = os.environ['GITHUB_CLIENT_SECRET'] rcpart.config['GITHUB_BASE_URL'] = os.environ['GITHUB_BASE_URL'] rcpart.config['PROPAGATE_EXCEPTIONS'] = True application = rcpart es = elasticsearch.Elasticsearch([os.environ['ES_HOST']]) partCategories_string = "" partCategories = {} github_cache = pylru.lrucache(64) from git import Repo github = GitHub(rcpart) SOCIAL_BOTS = ["facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)", "facebookexternalhit/1.1", "Mozilla/5.0 (compatible; redditbot/1.0; +http://www.reddit.com/feedback)", "Twitterbot", "Pinterest", "Google (+https://developers.google.com/+/web/snippet/)", "Mozilla/5.0 (compatible; Google-Structured-Data-Testing-Tool +http://developers.google.com/structured-data/testing-tool/)"] def is_social_bot(): for bot in SOCIAL_BOTS: if bot in request.user_agent.string: return True return False
# -*- coding: utf-8 -*- from flask_restful import Api from flask.ext.github import GitHub from odot.api import TodoStore, Model api = Api() github = GitHub() store = TodoStore(Model=Model)
es = elasticsearch.Elasticsearch([os.environ['ES_HOST']]) SILENT_COMMIT_MESSAGE = "Silently upgrade - " partCategories_string = "" partCategories = {} buildSkeleton = {} infoSkeleton = {} github_cache = pylru.lrucache(64) from git import Repo github = GitHub(rcbuild) SOCIAL_BOTS = [ "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)", "facebookexternalhit/1.1", "Mozilla/5.0 (compatible; redditbot/1.0; +http://www.reddit.com/feedback)", "Twitterbot", "Pinterest", "Google (+https://developers.google.com/+/web/snippet/)", "Mozilla/5.0 (compatible; Google-Structured-Data-Testing-Tool +http://developers.google.com/structured-data/testing-tool/)" ] def is_social_bot(): for bot in SOCIAL_BOTS: if bot in request.user_agent.string: return True
from bson.objectid import ObjectId logging.basicConfig(stream=sys.stdout, level=logging.INFO) app = Flask(__name__, template_folder='../templates', static_folder='../static') api = restful.Api(app) app.config['MONGO_URI'] = os.getenv('MONGO_URI', 'mongodb://localhost:27017') mongo = PyMongo(app) app.config['GITHUB_CLIENT_ID'] = os.getenv('GITHUB_CLIENT_ID') app.config['GITHUB_CLIENT_SECRET'] = os.getenv('GITHUB_CLIENT_SECRET') github_oauth = GitHub(app) @app.before_request def before_request(): g.user = None if 'user_id' in session: user = mongo.db.users.find_one({'_id': ObjectId(session['user_id'])}) g.user = user @github_oauth.access_token_getter def token_getter(): user = g.user if user is not None: user = user['github_access_token']