def test_lazy_load(self): oauth = OAuth() twitter = oauth.remote_app('twitter', base_url='https://api.twitter.com/1/', app_key='twitter') assert twitter.base_url == 'https://api.twitter.com/1/' app = Flask(__name__) app.config.update({ 'twitter': dict( request_token_params={'realms': 'email'}, consumer_key='twitter key', consumer_secret='twitter secret', request_token_url='request url', access_token_url='token url', authorize_url='auth url', ) }) oauth.init_app(app) assert twitter.consumer_key == 'twitter key' assert twitter.consumer_secret == 'twitter secret' assert twitter.request_token_url == 'request url' assert twitter.access_token_url == 'token url' assert twitter.authorize_url == 'auth url' assert twitter.content_type is None assert 'realms' in twitter.request_token_params
def test_lazy_load(self): oauth = OAuth() twitter = oauth.remote_app( 'twitter', base_url='https://api.twitter.com/1/', app_key='twitter' ) assert twitter.base_url == 'https://api.twitter.com/1/' app = Flask(__name__) app.config.update({ 'twitter': dict( consumer_key='twitter key', consumer_secret='twitter secret', request_token_url='request url', access_token_url='token url', authorize_url='auth url', ) }) oauth.init_app(app) assert twitter.consumer_key == 'twitter key' assert twitter.consumer_secret == 'twitter secret' assert twitter.request_token_url == 'request url' assert twitter.access_token_url == 'token url' assert twitter.authorize_url == 'auth url' assert twitter.content_type is None
def record_params(setup_state): """ Load used app configs into local config on registration from server/__init__.py """ global provider_name global provider_auth global oauth oauth = OAuth() app = setup_state.app provider_name = app.config.get('OAUTH_PROVIDER', MICROSOFT) provider_auth = oauth.remote_app(provider_name, app_key=provider_name) oauth.init_app(app) #instead of decorator set the fn pointer to the func here: provider_auth._tokengetter = provider_token
def record_params(setup_state): """ Load used app configs into local config on registration from server/__init__.py """ global provider_name global provider_auth global oauth oauth = OAuth() app = setup_state.app provider_name = app.config.get('OAUTH_PROVIDER', GOOGLE) provider_auth = oauth.remote_app( provider_name, app_key=provider_name ) oauth.init_app(app) #instead of decorator set the fn pointer to the func here: provider_auth._tokengetter = provider_token
def test_lazy_load_with_plain_text_config(self): oauth = OAuth() twitter = oauth.remote_app('twitter', app_key='TWITTER') app = Flask(__name__) app.config['TWITTER_CONSUMER_KEY'] = 'twitter key' app.config['TWITTER_CONSUMER_SECRET'] = 'twitter secret' app.config['TWITTER_REQUEST_TOKEN_URL'] = 'request url' app.config['TWITTER_ACCESS_TOKEN_URL'] = 'token url' app.config['TWITTER_AUTHORIZE_URL'] = 'auth url' oauth.init_app(app) assert twitter.consumer_key == 'twitter key' assert twitter.consumer_secret == 'twitter secret' assert twitter.request_token_url == 'request url' assert twitter.access_token_url == 'token url' assert twitter.authorize_url == 'auth url'
from flask import Flask, abort, url_for, jsonify from flask_oauthlib.client import OAuth app = Flask(__name__) class Config(object): SECRET_KEY = "tlnl;ht90134ukgl;aeyopyuip]ghm" DEBUG = True app.config.from_object(Config) oauth = OAuth() oauth.init_app(app) github = oauth.remote_app( name="github", consumer_key="96b9929c35ab135576b5", consumer_secret="da052fb4eff92b69e8bfcbc43447a68ba7b87335", request_token_params={"scope": "user"}, base_url="https://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") providers = {"github": github} profile_endpoints = {"github": "user"}
import pprint import os import time import pymongo import sys app = Flask(__name__) #initialize scheduler with your preferred timezone scheduler = BackgroundScheduler( {'apscheduler.timezone': 'America/Los_Angeles'}) scheduler.start() app.secret_key = os.environ['SECRET_KEY'] #used to sign session cookies oauth = OAuth(app) oauth.init_app( app) #initialize the app to be able to make requests for user information #Set up GitHub as OAuth provider github = oauth.remote_app( 'github', consumer_key=os. environ['GITHUB_CLIENT_ID'], #your web app's "username" for github's OAuth consumer_secret=os.environ[ 'GITHUB_CLIENT_SECRET'], #your web app's "password" for github's OAuth request_token_params={ 'scope': 'user:email' }, #request read-only access to the user's email. For a list of possible scopes, see developer.github.com/apps/building-oauth-apps/scopes-for-oauth-apps base_url='https://api.github.com/', request_token_url=None, access_token_method='POST', access_token_url='https://github.com/login/oauth/access_token',
from maproulette import app from flask_oauthlib.client import OAuth from flask import request, url_for, redirect, session from maproulette.models import db, User from geoalchemy2.elements import WKTElement from geoalchemy2.shape import to_shape # instantiate OAuth object oauth = OAuth() osm = oauth.remote_app( 'osm', app_key='OSM' ) oauth.init_app(app) @osm.tokengetter def get_osm_token(token=None): return session.get('osm_token') @app.route('/signin') def oauth_authorize(): """Redirect to the authorize URL""" callback_url = url_for('oauthorized', next=request.args.get('next')) return osm.authorize(callback=callback_url or request.referrer or None) @app.route('/oauthorized') @osm.authorized_handler
def init_login(app): login_manager = LoginManager() login_manager.login_view = 'login.login' login_manager.anonymous_user = users.MyAnonymousUser @login_manager.user_loader def load_user(_id): return users.get(_id=_id) login_manager.init_app(app) login_blueprint = Blueprint("login", __name__) 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' ) oauth.init_app(app) @twitter.tokengetter def get_access_token(token=None): if current_user.is_authenticated(): token = current_user['token'] return token['oauth_token'], token['oauth_token_secret'] else: return None @login_blueprint.route('/oauth-authorized') @twitter.authorized_handler def oauth_authorized(resp): next_url = request.args.get('next') if resp is None: flash(u'You denied the request to sign in.') return redirect(next_url) token = ( resp['oauth_token'], resp['oauth_token_secret'] ) username = resp['screen_name'] email = username + "@papertalk.org" user = users.get(username=username) if not user: user = users.create(username, email, token) login_user(user) return redirect(next_url) @login_blueprint.route('/login') def login(): if current_user.is_authenticated(): return request.referrer callback_url = url_for('.oauth_authorized', next=request.args.get('next') or request.referrer) #callback_url = callback_url.replace("http://", "https://") #print callback_url return twitter.authorize(callback=callback_url or request.referrer or None) app.register_blueprint(login_blueprint)
def instance(app): """:rtype: OAuth""" oauth = OAuth() oauth.remote_app('github', app_key='GITHUB_OAUTH') oauth.init_app(app) return oauth