def register_service(name): if name == 'google': return google.register_to(social) if name == 'twitter': return twitter.register_to(social) if name == 'facebook': return facebook.register_to(social) if name == 'github': return github.register_to(social) if name == 'weibo': return weibo.register_to(social)
from server.models import User app = OAuth() facebook_data = { 'fetch_query': '/me?fields=email,id,first_name,last_name,gender', 'oauth': facebook_app.register_to(app, app_key='FACEBOOK_OAUTH_PARAMS'), 'custom_fields': { 'first_name': 'first_name', 'last_name': 'last_name' } } google_data = { 'fetch_query': 'userinfo', 'oauth': google_app.register_to(app, app_key='GOOGLE_OAUTH_PARAMS'), 'custom_fields': { 'first_name': 'given_name', 'last_name': 'family_name' } } oauth_apps = {'facebook': facebook_data, 'google': google_data} def load_user(user_id): return User.query.filter_by(id=user_id, active=True).first() def requires_roles(*roles): def wrapper(f):
# limitations under the License. from functools import wraps from flask import session, request, jsonify, url_for, abort, redirect, Blueprint, g, current_app, abort from flask_oauthlib.client import OAuth from flask_oauthlib.contrib.apps import google from data.database import DEFAULT_DATABASE from data.models import User bp = Blueprint('auth', __name__, url_prefix='/auth') db = DEFAULT_DATABASE.db oauth = OAuth() google = google.register_to(oauth, name='GOOGLE_OAUTH') @bp.record def init_auth(state): oauth.init_app(state.app) @bp.route('/login', methods=['GET']) def login(): if is_authenticated(): return redirect('/') return google.authorize( callback=url_for('auth.authorized', _external=True))
from project.extensions import oauth from flask_oauthlib.contrib.apps import google as google_app google = google_app.register_to(oauth, name='GOOGLE_OAUTH_PARAMS')