def create_app(): app = Flask(__name__) app.config.from_object('over_achiever.config') db = SQLAlchemy(app, metadata=models.metadata) db.create_all() resources.db = app.db = db oauth = OAuth(app) google = oauth.remote_app( 'google', consumer_key=os.getenv("GOOGLE_CLIENT_ID", ""), consumer_secret=os.getenv("GOOGLE_CLIENT_SECRET", ""), request_token_params={'scope': 'email'}, base_url='https://www.googleapis.com/oauth2/v1/', request_token_url=None, access_token_method='POST', access_token_url='https://accounts.google.com/o/oauth2/token', authorize_url='https://accounts.google.com/o/oauth2/auth', ) # set the token getter for the auth client google._tokengetter = lambda: session.get('google_token') resources.google = app.google = google api = Api(app) resource_map = ( (User, '/v1.0/users'), (Goal, '/v1.0/goals'), ) for resource, route in resource_map: api.add_resource(resource, route) return app
def create_app(): app = Flask(__name__) app.config.from_object('over_achiever.config') db = SQLAlchemy(app, metadata=models.metadata) db.create_all() resources.db = app.db = db oauth = OAuth(app) github = oauth.remote_app( 'github', consumer_key='507e57ab372adeb8051b', consumer_secret='08a7dbaa06ac16daab00fac53724ee742c8081c5', request_token_params={'scope': 'user:email'}, base_url='https://api.github.com/', request_token_url=None, access_token_method='POST', access_token_url='https://github.com/login/oauth/access_token', authorize_url='https://github.com/login/oauth/authorize' ) # set the token getter for the auth client github._tokengetter = lambda: session.get('github_token') resources.github = app.github = github api = Api(app) resource_map = ( (User, '/v1.0/users'), (Goal, '/v1.0/goals'), ) for resource, route in resource_map: api.add_resource(resource, route) return app
def create_app(): app = Flask(__name__) app.config.from_object('over_achiever.config') db = SQLAlchemy(app, metadata=models.metadata) db.create_all() resources.db = app.db = db oauth = OAuth(app) github = oauth.remote_app( 'github', consumer_key='507e57ab372adeb8051b', consumer_secret='08a7dbaa06ac16daab00fac53724ee742c8081c5', request_token_params={'scope': 'user:email'}, base_url='https://api.github.com/', request_token_url=None, access_token_method='POST', access_token_url='https://github.com/login/oauth/access_token', authorize_url='https://github.com/login/oauth/authorize') # set the token getter for the auth client github._tokengetter = lambda: session.get('github_token') resources.github = app.github = github api = Api(app) resource_map = ( (User, '/v1.0/users'), (Goal, '/v1.0/goals'), ) for resource, route in resource_map: api.add_resource(resource, route) return app
def register_oauth(app): oauth = OAuth(app) dropbox = oauth.remote_app('dropbox', app_key='DROPBOX') facebook = oauth.remote_app('facebook', app_key='FACEBOOK') app.oauth = oauth app.oauth.providers = { 'dropbox' : dropbox, 'facebook': facebook, }
def oauth_app(self, base_url='https://api.twitter.com/1.1/'): oauth = OAuth() twitter = oauth.remote_app( 'twitter', base_url='', 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=self.app.config.get('TWITTER_CONSUMER_KEY'), consumer_secret=self.app.config.get('TWITTER_CONSUMER_SECRET'), ) twitter.tokengetter(self.token_getter) return twitter
def setup_oauth(app): oauth = OAuth(app) google = oauth.remote_app( 'google', consumer_key=app.config.get('GOOGLE_OAUTH_KEY'), consumer_secret=app.config.get('GOOGLE_OAUTH_SECRET'), request_token_params={ 'scope': 'https://www.googleapis.com/auth/userinfo.email'}, base_url='https://www.googleapis.com/oauth2/v1/', request_token_url=None, access_token_method='POST', access_token_url='https://accounts.google.com/o/oauth2/token', authorize_url='https://accounts.google.com/o/oauth2/auth', ) @app.route('/login') def login(): url = flask.url_for('authorized', _external=True) return google.authorize(callback=url) @app.route('/logout') def logout(): flask.session.pop('identity', None) return flask.redirect(flask.url_for('views.home')) @app.route('/login/google') @google.authorized_handler def authorized(resp): if resp is None: return 'Access denied: reason=%s error=%s' % ( flask.request.args['error_reason'], flask.request.args['error_description'], ) flask.session['identity'] = { 'google_token': (resp['access_token'], ''), } me = google.get('userinfo') flask.session['identity']['name'] = me.data['name'] flask.session['identity']['email'] = me.data['email'] flask.session['identity']['picture'] = me.data['picture'] return flask.redirect(flask.url_for('views.home')) @google.tokengetter def get_google_oauth_token(): return flask.session.get('identity', {}).get('google_token')
from jinja2 import FileSystemLoader import os import six import json import logging import cryptacular.bcrypt import sqlalchemy root = os.path.abspath(os.path.dirname(__file__) + '/../') db = SQLAlchemy() lm = LoginManager() oauth_lib = OAuth() crypt = cryptacular.bcrypt.BCRYPTPasswordManager() # OAuth configuration, must be outside function to be importable github = oauth_lib.remote_app( 'github', app_key='github' ) twitter = oauth_lib.remote_app( 'twitter', app_key='twitter' ) google = oauth_lib.remote_app( 'google', app_key='google' )
def configure(app): """ will build oauthlib remote apps from config vairable in form of OAUTH = { "google": { "consumer_key": 'xxxxxxxxxxxx', "consumer_secret": 'xxxxxxxxxxxxxxxxxxxx', "request_token_params": { 'scope': ('https://www.googleapis.com/auth/userinfo.email ' 'https://www.googleapis.com/auth/userinfo.profile') }, "base_url": 'https://www.googleapis.com/oauth2/v1/', "request_token_url": None, "access_token_method": 'POST', "access_token_url": 'https://accounts.google.com/o/oauth2/token', "authorize_url": 'https://accounts.google.com/o/oauth2/auth', "_info_endpoint": "userinfo" }, "facebook": { "consumer_key": "xxxxxxxxxxxxxxxxxxxxxxxx", "consumer_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxx", "request_token_params": {'scope': 'email'}, "base_url": 'https://graph.facebook.com', "request_token_url": None, "access_token_url": '/oauth/access_token', "authorize_url": 'https://www.facebook.com/dialog/oauth', "_info_endpoint": "/me" }, "github": {}, "linkedin": {}, "dropbox": {}, "twitter": {} } """ app.add_quokka_url_rule( '/accounts/oauth/login/<provider>/', 'oauth_login', oauth_login ) config = app.config.get("OAUTH") if not config: return oauth = OAuth(app) for provider, data in config.items(): provider_name = "oauth_" + provider oauth_app = oauth.remote_app( provider, **{k: v for k, v in data.items() if not k.startswith("_")} ) token_var = "oauth_{}_token".format(provider) oauth_app.tokengetter(lambda: session.get(token_var)) setattr(app, provider_name, oauth_app) app.add_quokka_url_rule( '/accounts/oauth/authorized/{0}/'.format(provider), '{0}_authorized'.format(provider), oauth_app.authorized_handler(make_oauth_handler(provider)) ) if provider == 'linkedin': def change_linkedin_query(uri, headers, body): auth = headers.pop('Authorization') headers['x-li-format'] = 'json' if auth: auth = auth.replace('Bearer', '').strip() if '?' in uri: uri += '&oauth2_access_token=' + auth else: uri += '?oauth2_access_token=' + auth return uri, headers, body oauth_app.pre_request = change_linkedin_query
# -*- coding: utf-8 -*- from flask import Flask # flask-SQLAlchemy from flask.ext.sqlalchemy import SQLAlchemy db = SQLAlchemy() # flask-oauth from flask.ext.oauthlib.client import OAuth oauth = OAuth() # flask-login from flask.ext.login import LoginManager login_manager = LoginManager() login_manager.session_protection = 'strong' login_manager.login_view = 'user.login' # flask-mail from flask.ext.mail import Mail mail = Mail() # app factory class class App(object): def __init__(self, **kwargs): self.app = Flask(__name__, instance_relative_config=False) # config -- public config # from phzblog import config # self.app.config.from_object(config) self.app.config.from_object('config') # instance/config.py -- private config self.app.config.from_pyfile('../instance/config.py') # config/xxx.py -- scence config # self.app.config.from_envvar('APP_CONFIG_FILE') # APP_CONFIG_FILE defined in start.sh
def instance(app): """:rtype: OAuth""" oauth = OAuth() oauth.remote_app('github', app_key='GITHUB_OAUTH') oauth.init_app(app) return oauth
from datetime import datetime from os.path import dirname, abspath, join cwd = abspath(dirname(__file__)) from flask import * from flask.ext.oauthlib.client import OAuth from flask.ext.sqlalchemy import SQLAlchemy import flask.ext.login as fl from sqlalchemy.exc import IntegrityError app = Flask(__name__) app.debug = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + join(cwd, 'circles.db') oauth = OAuth(app) db = SQLAlchemy(app) login_manager = fl.LoginManager() login_manager.init_app(app) import string from random import SystemRandom secure_random = SystemRandom() key_chars = string.ascii_letters + string.digits def key_gen(n): return ''.join(secure_random.choice(key_chars) for i in range(n)) # load stored configuration try:
from flask import request, url_for, session, jsonify, render_template, redirect, \ g, flash from flask.ext.oauthlib.client import OAuth, OAuthException from flask.ext.babel import lazy_gettext as _l, gettext as _ from . import route from .models import User2, db oauth = OAuth() 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/authenticate', app_key="TWITTER") github = oauth.remote_app('github', base_url='https://api.github.com/', request_token_params={'scope': 'user:email'}, request_token_url=None, access_token_method='POST', access_token_url='https://github.com/login/oauth/access_token', authorize_url='https://github.com/login/oauth/authorize', app_key='GITHUB') linkedin = oauth.remote_app('linkedin', base_url='https://api.linkedin.com/v1/', request_token_params={ 'scope': 'r_basicprofile',
reload(sys) sys.setdefaultencoding("utf-8") app = Flask('apps') app.config.from_object('apps.settings.Production') login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' login_manager.login_message = 'You need to login.' app_signals = Namespace() # open auth oauth = OAuth(app) google = oauth.remote_app( 'google', consumer_key=app.config.get('GOOGLE_CLIENT_ID'), consumer_secret=app.config.get('GOOGLE_CLIENT_SECRET'), request_token_params={ 'scope': 'https://www.googleapis.com/auth/userinfo.email' }, base_url='https://www.googleapis.com/oauth2/v1/', request_token_url=None, access_token_method='POST', access_token_url='https://accounts.google.com/o/oauth2/token', authorize_url='https://accounts.google.com/o/oauth2/auth', ) facebook = oauth.remote_app( 'facebook',
from flask import Blueprint, request, current_app, redirect, session, url_for, abort from flask.ext.oauthlib.client import OAuth, OAuthException from flask.ext.security.utils import login_user, logout_user from werkzeug.urls import url_encode from udata.auth import current_user from udata.models import datastore from udata.commands import manager log = logging.getLogger(__name__) bp = Blueprint('youckan', __name__) oauth = OAuth() youckan = oauth.remote_app( 'youckan', app_key='YOUCKAN', request_token_url=None, access_token_method='POST', ) def encode_state(session_id=None, url=None): next_url = (url or request.url).replace('http://', 'https://') state = { 'timestamp': time.time(), 'next_url': next_url }
from flask import (Blueprint, request, session, g, render_template, url_for, redirect, jsonify) from werkzeug.contrib.cache import SimpleCache from flask.ext.oauthlib.client import OAuth, OAuthException bp = Blueprint('user', __name__) oauth = OAuth() github = oauth.remote_app( 'github', app_key='GITHUB', request_token_params={'scope': ''}, base_url='https://api.github.com/', request_token_url=None, access_token_method='POST', access_token_url='https://github.com/login/oauth/access_token', authorize_url='https://github.com/login/oauth/authorize', ) _cache = SimpleCache() @github.tokengetter def get_github_oauth_token(): return session.get('github_token') def authenticated(): """사용자가 GitHub 계정으로 인증한 상태인지 확인한다""" try:
auth = "Bearer {}".format(token) url = '{base_url}/import/bal'.format(base_url=app.config['BAN_URL']) resp = requests.post(url, headers={'Authorization': auth}, files={'data': ('f.csv', request.files['data'])}) return resp.text return render_template('ban/batch.html') @app.route('/ban/groups') def ban_groups(): return render_template('ban/groups.html') # Oauth oauth = OAuth(app) # Data.gouv.fr dgfr = oauth.remote_app( 'dgfr', base_url='https://www.data.gouv.fr/api/1/', request_token_url=None, request_token_params={'scope': 'default'}, access_token_method='POST', access_token_url='https://www.data.gouv.fr/oauth/token', authorize_url='https://www.data.gouv.fr/oauth/authorize', app_key='DATAGOUV' ) @dgfr.tokengetter
PROVIDERS=['dgfr', 'france-connect', 'osm']) @app.route('/crowdsourcing/data/') def crowdsourcing_data(): data = Crowdsourcing.data(request.args.get('from', None)) return json.dumps([c.to_json() for c in data]) @app.route('/news/') def news(): return render_template('news.html') # Oauth oauth = OAuth(app) # Data.gouv.fr dgfr = oauth.remote_app( 'dgfr', base_url='https://www.data.gouv.fr/api/1/', request_token_url=None, request_token_params={'scope': 'default'}, access_token_method='POST', access_token_url='https://www.data.gouv.fr/oauth/token', authorize_url='https://www.data.gouv.fr/oauth/authorize', app_key='DATAGOUV' ) # France Connect fc = oauth.remote_app(
from os import environ from celery import Celery from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.oauthlib.client import OAuth env = environ.get('GMW_APP_ENV', 'development').capitalize() app = Flask(__name__) app.config.from_object('gitmostwanted.config.Config' + env) app.config.from_envvar('GMW_APP_SETTINGS', silent=True) db = SQLAlchemy(app) oauth = OAuth() oauth.remote_app('github', app_key='GITHUB_OAUTH') oauth.init_app(app) celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL']) celery.conf.update(app.config)
PROVIDERS=['dgfr', 'france-connect', 'osm']) @app.route('/crowdsourcing/data/') def crowdsourcing_data(): data = Crowdsourcing.data(request.args.get('from', None)) return json.dumps([c.to_json() for c in data]) @app.route('/news/') def news(): return render_template('news.html') # Oauth oauth = OAuth(app) # Data.gouv.fr dgfr = oauth.remote_app( 'dgfr', base_url='https://www.data.gouv.fr/api/1/', request_token_url=None, request_token_params={'scope': 'default'}, access_token_method='POST', access_token_url='https://www.data.gouv.fr/oauth/token', authorize_url='https://www.data.gouv.fr/oauth/authorize', app_key='DATAGOUV') # France Connect fc = oauth.remote_app( 'franceconnect',
# error logging ############################################################################################################## ERROR_LOG_DIR = './log/' app.config['ERROR_LOG_DIR'] = ERROR_LOG_DIR if not app.debug: import logging file_handler = logging.FileHandler(os.path.join(app.root_path, app.config['ERROR_LOG_DIR'], "log.txt")) #file_handler = logging.handlers.TimedRotatingFileHandler(os.path.join(app.root_path, app.config['ERROR_LOG_DIR'], "log.txt")) file_handler.setLevel(logging.ERROR) app.logger.addHandler(file_handler) ############################################################################################################## # open auth oauth = OAuth(app) # # @OAuth Provider # facebook = oauth.remote_app( 'facebook', consumer_key=app.config.get('FACEBOOK_APP_ID'), consumer_secret=app.config.get('FACEBOOK_APP_SECRET'), request_token_params={ 'scope': [ 'public_profile', 'publish_actions', 'user_friends' ] }, base_url='https://graph.facebook.com/', request_token_url=None, access_token_url='/oauth/access_token', authorize_url='https://www.facebook.com/dialog/oauth', )
from flask import Blueprint from flask import render_template from flask import url_for, session, request, redirect, flash from flask.ext.oauthlib.client import OAuth from .models import Resume frontend_views = Blueprint('frontend', __name__, url_prefix='/') oauth_views = Blueprint('oauth', __name__, url_prefix='/oauth/') oauth = OAuth() github = oauth.remote_app( 'github', consumer_key='08db72ce47a207704fb4', consumer_secret='f5e5eff75760ea886e033a6ec87b23d33d4903a0', request_token_params={'scope': 'user:email'}, base_url='https://api.github.com/', request_token_url=None, access_token_method='POST', access_token_url='https://github.com/login/oauth/access_token', authorize_url='https://github.com/login/oauth/authorize' ) @frontend_views.route('/') def index(): return render_template('index.jade', page_title='Welcome to Horus')
# coding: utf-8 import os from flask import Flask from flask import session from flask.ext.oauthlib.client import OAuth from piko import App app = App('piko') oauth = OAuth(app) def twitter(): if app.config.get('TWITTER_API_KEY', False): twitter = oauth.remote_app( 'twitter', register=False, consumer_key=app.config.get('TWITTER_API_KEY', None), consumer_secret=app.config.get('TWITTER_API_SECRET', None), 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/authenticate', ) @twitter.tokengetter def get_twitter_token(): if 'twitter_oauth' in session: resp = session['twitter_oauth_token']
from flask import Blueprint from flask import render_template from flask import url_for, session, request, redirect, flash from flask.ext.oauthlib.client import OAuth from .models import Resume frontend_views = Blueprint('frontend', __name__, url_prefix='/') oauth_views = Blueprint('oauth', __name__, url_prefix='/oauth/') oauth = OAuth() github = oauth.remote_app( 'github', consumer_key='08db72ce47a207704fb4', consumer_secret='f5e5eff75760ea886e033a6ec87b23d33d4903a0', request_token_params={'scope': 'user:email'}, base_url='https://api.github.com/', request_token_url=None, access_token_method='POST', access_token_url='https://github.com/login/oauth/access_token', authorize_url='https://github.com/login/oauth/authorize') @frontend_views.route('/') def index(): return render_template('index.jade', page_title='Welcome to Horus') @frontend_views.route('resume/') def list_resumes():
def configure(app): """ will build oauthlib remote apps from config vairable in form of OAUTH = { "google": { "consumer_key": 'xxxxxxxxxxxx', "consumer_secret": 'xxxxxxxxxxxxxxxxxxxx', "request_token_params": { 'scope': ('https://www.googleapis.com/auth/userinfo.email ' 'https://www.googleapis.com/auth/userinfo.profile') }, "base_url": 'https://www.googleapis.com/oauth2/v1/', "request_token_url": None, "access_token_method": 'POST', "access_token_url": 'https://accounts.google.com/o/oauth2/token', "authorize_url": 'https://accounts.google.com/o/oauth2/auth', "_info_endpoint": "userinfo" }, "facebook": { "consumer_key": "xxxxxxxxxxxxxxxxxxxxxxxx", "consumer_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxx", "request_token_params": {'scope': 'email'}, "base_url": 'https://graph.facebook.com', "request_token_url": None, "access_token_url": '/oauth/access_token', "authorize_url": 'https://www.facebook.com/dialog/oauth', "_info_endpoint": "/me" }, "github": {}, "linkedin": {}, "dropbox": {}, "twitter": {} } """ app.add_quokka_url_rule('/accounts/oauth/login/<provider>/', 'oauth_login', oauth_login) config = app.config.get("OAUTH") if not config: return oauth = OAuth(app) for provider, data in config.items(): provider_name = "oauth_" + provider oauth_app = oauth.remote_app( provider, **{k: v for k, v in data.items() if not k.startswith("_")}) token_var = "oauth_{}_token".format(provider) oauth_app.tokengetter(lambda: session.get(token_var)) setattr(app, provider_name, oauth_app) app.add_quokka_url_rule( '/accounts/oauth/authorized/{0}/'.format(provider), '{0}_authorized'.format(provider), oauth_app.authorized_handler(make_oauth_handler(provider))) if provider == 'linkedin': def change_linkedin_query(uri, headers, body): auth = headers.pop('Authorization') headers['x-li-format'] = 'json' if auth: auth = auth.replace('Bearer', '').strip() if '?' in uri: uri += '&oauth2_access_token=' + auth else: uri += '?oauth2_access_token=' + auth return uri, headers, body oauth_app.pre_request = change_linkedin_query
from flask import json import midauth.models.user from midauth.utils import importlib from . import defaults from . import dispatch from .ext import OAuth2Provider login_manager = LoginManager() login_manager.anonymous_user = midauth.models.user.AnonymousUser current_user = flask.ext.login.current_user oauth2 = OAuth2Provider() oauth_client = OAuth() def create_app(config): app = flask.Flask('midauth.web') app.config.from_object(defaults) if isinstance(config, collections.Mapping): app.config.update(config) else: app.config.from_pyfile(config) login_manager.init_app(app) oauth2.init_app(app) init_oauth_client(app) init_sqla_session(app, app.config['DATABASE_URL']) init_error_handlers(app) init_blueprints(app, app.config['BLUEPRINTS'])
# -*- coding: utf-8 -*- __author__ = 'Jaeyoung' from flask.ext.oauthlib.client import OAuth from settings import FACEBOOK_OAUTH facebook_oauth = OAuth() facebook = facebook_oauth.remote_app( 'facebook', base_url='https://graph.facebook.com/', request_token_url=None, access_token_url='/oauth/access_token', authorize_url='https://www.facebook.com/dialog/oauth', consumer_key=FACEBOOK_OAUTH.get('APP_ID', ''), consumer_secret=FACEBOOK_OAUTH.get('APP_SECRET', ''), request_token_params={'scope': 'email'}) class FacebookProfileFetcher(object): def __init__(self, access_token, fields): self.access_token = access_token self.fields = fields def fetch(self): fields_str = ','.join(self.fields) param = { 'access_token': self.access_token, 'locale': 'ko_KR', 'fields': fields_str, } r = facebook.get('/me', data=param)
def setup_admin(app): principals.init_app(app) oauth = OAuth(app) google = oauth.remote_app( 'google', consumer_key=app.config['GLOGIN_CLIENT_ID'], consumer_secret=app.config['GLOGIN_CLIENT_SECRET'], request_token_params={ 'scope': 'https://www.googleapis.com/auth/userinfo.email'}, base_url='https://www.googleapis.com/oauth2/v1/', request_token_url=None, access_token_method='POST', access_token_url='https://accounts.google.com/o/oauth2/token', authorize_url='https://accounts.google.com/o/oauth2/auth', ) @app.route('/admin/login') def login(): return flask.render_template('admin_login.html') @app.route('/admin/login/google') def login_google(): url = flask.url_for('authorized', _external=True) return google.authorize(callback=url) @app.route('/admin/logout') def logout(): google_token = flask.session.pop('identity', {}).get('google_token') if google_token: requests.get( 'https://accounts.google.com/o/oauth2/revoke', params={'token': google_token[0]} ) return flask.redirect(flask.url_for('admin.home')) @app.route('/admin/login/google_callback') @google.authorized_handler def authorized(resp): if resp is None: return 'Access denied: reason=%s error=%s' % ( flask.request.args['error_reason'], flask.request.args['error_description'], ) flask.session['identity'] = { 'google_token': (resp['access_token'], ''), } me = google.get('userinfo') flask.session['identity']['name'] = me.data['name'] flask.session['identity']['email'] = me.data['email'] flask.session['identity']['picture'] = me.data['picture'] return flask.redirect(flask.url_for('admin.home')) @google.tokengetter def get_google_oauth_token(): return flask.session.get('identity', {}).get('google_token') @principals.identity_loader def load_identity(): devel_identity = app.config.get('DEVEL_IDENTITY') if devel_identity: identity = Identity(devel_identity) identity.provides.add(role.admin) return identity data = flask.session.get('identity') if data is not None: identity = Identity(data['email']) if data['email'] in app.config.get('ADMIN_EMAILS'): identity.provides.add(role.admin) return identity app.register_blueprint(admin)
from flask import Blueprint from flask import url_for, session, request from flask import redirect, flash from flask.ext.oauthlib.client import OAuth from flask.ext.babel import gettext as _ oauth_views = Blueprint('oauth', __name__, url_prefix='/oauth/') oauth = OAuth() github = oauth.remote_app( 'github', app_key='GITHUB', ) @oauth_views.route('login/') def github_login(): return github.authorize(callback=url_for('oauth.github_authorized', _external=True)) @oauth_views.route('logout') def github_logout(): session.pop('github_token', None) return redirect(url_for('frontend.index')) @oauth_views.route('login/authorized') def github_authorized(): resp = github.authorized_response()
# -*- coding: utf-8 -*- __author__ = 'Jaeyoung' from flask.ext.oauthlib.client import OAuth from settings import FACEBOOK_OAUTH facebook_oauth = OAuth() facebook = facebook_oauth.remote_app('facebook', base_url='https://graph.facebook.com/', request_token_url=None, access_token_url='/oauth/access_token', authorize_url='https://www.facebook.com/dialog/oauth', consumer_key=FACEBOOK_OAUTH.get('APP_ID', ''), consumer_secret=FACEBOOK_OAUTH.get('APP_SECRET', ''), request_token_params={'scope': 'email'}) class FacebookProfileFetcher(object): def __init__(self, access_token, fields): self.access_token = access_token self.fields = fields def fetch(self): fields_str = ','.join(self.fields) param = { 'access_token': self.access_token, 'locale': 'ko_KR', 'fields': fields_str, } r = facebook.get('/me', data=param) return r