def enable_github_oauth(GITHUB_ENABLE): if not GITHUB_ENABLE: return None, None from flask_oauthlib.client import OAuth oauth = OAuth(app) github = oauth.remote_app( 'github', consumer_key=app.config['GITHUB_OAUTH_KEY'], consumer_secret=app.config['GITHUB_OAUTH_SECRET'], request_token_params={'scope': app.config['GITHUB_OAUTH_SCOPE']}, base_url=app.config['GITHUB_OAUTH_URL'], request_token_url=None, access_token_method='POST', access_token_url=app.config['GITHUB_OAUTH_TOKEN'], authorize_url=app.config['GITHUB_OAUTH_AUTHORIZE'] ) @app.route('/user/authorized') def authorized(): session['github_oauthredir'] = url_for('.authorized', _external=True) resp = github.authorized_response() if resp is None: return 'Access denied: reason=%s error=%s' % ( request.args['error'], request.args['error_description'] ) session['github_token'] = (resp['access_token'], '') return redirect(url_for('.login')) @github.tokengetter def get_github_oauth_token(): return session.get('github_token') return oauth, github
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 get_collection_tweets(): tweets = [] oauth = OAuth(current_app) 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', consumer_key=current_app.config['TWITTER_CONSUMER_KEY'], consumer_secret=current_app.config['TWITTER_CONSUMER_SECRET'] ) @twitter.tokengetter def get_twitter_token(): return ( current_app.config['TWITTER_ACCESS_TOKEN'], current_app.config['TWITTER_ACCESS_TOKEN_SECRET'] ) response = twitter.request('statuses/user_timeline.json', data={ 'screen_name': current_app.config['TWITTER_SCREEN_NAME'], 'count': current_app.config['TWITTER_LIMIT'], }) if response.status == 200: tweets = response.data return tweets
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 make_twitter(flask_app): oauth = OAuth(flask_app) return 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', consumer_key=os.getenv('TWITTER_CONSUMER_KEY'), consumer_secret=os.getenv('TWITTER_CONSUMER_SECRET'))
def get_oauth_provider(provider): oauth = OAuth(current_app) if provider == 'github': github = oauth.remote_app( 'github', consumer_key=_cfg('gh-oauth-id'), consumer_secret=_cfg('gh-oauth-secret'), 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' ) @github.tokengetter def get_github_oauth_token(): return session.get('github_token') return github if provider == 'google': google = oauth.remote_app( 'google', consumer_key=_cfg('google-oauth-id'), consumer_secret=_cfg('google-oauth-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', ) @google.tokengetter def get_google_oauth_token(): return session.get('google_token') return google raise Exception('This OAuth provider was not implemented: ' + provider)
def make_lepture(app, ck, cs): oauth = OAuth(app) return oauth.remote_app('lepture', consumer_key=ck, consumer_secret=cs, request_token_params={ 'realm': 'email'}, base_url='http://127.0.0.1:5000/api/', request_token_url='http://127.0.0.1:5000/oauth/request_token', access_token_method='GET', access_token_url='http://127.0.0.1:5000/oauth/access_token', authorize_url='http://127.0.0.1:5000/oauth/authorize')
def __init__(self): super().__init__('twitter') oauth = OAuth() self.service = oauth.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=app.config['TWITTER_CUSTOMER_KEY'], consumer_secret=app.config['TWITTER_CUSTOMER_SECRET'] ) self.service.tokengetter = TwitterSignIn.get_token
def create_client(app): oauth = OAuth(app) dev = oauth.remote_app( 'dev', consumer_key='dev', consumer_secret='dev', request_token_params={'scope': 'email'}, base_url='http://127.0.0.1:5000/api/', request_token_url=None, access_token_method='GET', access_token_url='http://127.0.0.1:5000/oauth/access_token', authorize_url='http://127.0.0.1:5000/oauth/authorize' ) @app.route('/') def index(): if 'dev_token' in session: ret = dev.get('email') return jsonify(ret.data) return redirect(url_for('login')) @app.route('/login') def login(): return dev.authorize(callback=url_for('authorized', _external=True)) @app.route('/logout') def logout(): session.pop('dev_token', None) return redirect(url_for('index')) @app.route('/authorized') @dev.authorized_handler def authorized(resp): if resp is None: return 'Access denied: error=%s' % ( request.args['error'] ) session['dev_token'] = (resp['access_token'], '') return jsonify(resp) @app.route('/address') def address(): ret = dev.get('address') return ret.raw_data @dev.tokengetter def get_oauth_token(): return session.get('dev_token') return app
class OAuthRegistry(object): def __init__(self): self.oauth = OAuth(self.app) # Map of remote apps indexed by service ID. self.remote = dict() # Create remote apps. for config_id in self.configs: print 'Registered OAuth: {0}'.format(config_id) self.app.config[config_id] = self.configs[config_id] remote = self.oauth.remote_app(config_id, app_key=config_id) self.remote[config_id] = remote
def install_github_oauth(app): oauth = OAuth(app) github_auth = oauth.remote_app( 'github', consumer_key=app.config['GITHUB_CLIENT_ID'], consumer_secret=app.config['GITHUB_CLIENT_SECRET'], request_token_params={'scope': 'repo,user'}, 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' ) @app.route('/login') def login(): return github_auth.authorize(callback=url_for('authorized', _external=True, next=request.args.get('next') or request.referrer or None)) @app.route('/logout') def logout(): session.pop('token', None) return redirect(url_for('index')) @app.route('/oauth_callback') @github_auth.authorized_handler def authorized(resp): next_url = request.args.get('next') or url_for('index') if resp is None: return 'Access denied: reason=%s error=%s' % ( request.args['error_reason'], request.args['error_description'] ) session['token'] = resp['access_token'] user_info = github.get_current_user_info(session['token']) if not user_info: return "Unable to get user info." session['login'] = user_info['login'] return redirect(next_url) @github_auth.tokengetter def get_github_oauth_token(): token = session.get('token') if token: return (token, '') else: return token
def initialize(app): app.secret_key = 'development' oauth = OAuth(app) host_eb_apis = { 'tourney': oauth.remote_app( 'eventbrite-tourney', consumer_key=settings.tourney_consumer_key, consumer_secret=settings.tourney_secret_key, request_token_params={ 'state': lambda: security.gen_salt(10) }, base_url='https://www.eventbriteapi.com/v3/', request_token_url=None, access_token_method='POST', access_token_url='https://www.eventbrite.com/oauth/token', authorize_url='https://www.eventbrite.com/oauth/authorize', ), 'secret-santa': oauth.remote_app( 'eventbrite-ss', consumer_key=settings.secret_santa_consumer_key, consumer_secret=settings.secret_santa_secret_key, request_token_params={ 'state': lambda: security.gen_salt(10) }, base_url='https://www.eventbriteapi.com/v3/', request_token_url=None, access_token_method='POST', access_token_url='https://www.eventbrite.com/oauth/token', authorize_url='https://www.eventbrite.com/oauth/authorize', ), } for _api in host_eb_apis.values(): _api.tokengetter(lambda *args: session.get('eventbrite_token')) return host_eb_apis
def create_oauth(app): oauth = OAuth(app) remote = oauth.remote_app( 'dev', consumer_key='dev', consumer_secret='dev', request_token_params={'realm': 'email'}, base_url='http://127.0.0.1:5000/api/', request_token_url='http://127.0.0.1:5000/oauth/request_token', access_token_method='GET', access_token_url='http://127.0.0.1:5000/oauth/access_token', authorize_url='http://127.0.0.1:5000/oauth/authorize' ) return remote
def create_client(self, app): oauth = OAuth(app) remote = oauth.remote_app( 'dev', consumer_key='noclient', consumer_secret='dev', request_token_params={'realm': 'email'}, base_url='http://localhost/api/', request_token_url='http://localhost/oauth/request_token', access_token_method='GET', access_token_url='http://localhost/oauth/access_token', authorize_url='http://localhost/oauth/authorize' ) return create_client(app, remote)
def __init__(self, consumer_key, consumer_secret): oauth = OAuth() self.api = oauth.remote_app('500px-fav-downloader', base_url='https://api.500px.com/v1/', request_token_url='https://api.500px.com/v1/oauth/request_token', access_token_url='https://api.500px.com/v1/oauth/access_token', authorize_url='https://api.500px.com/v1/oauth/authorize', consumer_key=consumer_key, consumer_secret=consumer_secret ) self.oauth_token = None self.oauth_token_secret = None # Register the function to get the tokens self.api.tokengetter(self.get_oauth_token)
def test_app(): app = Flask(__name__) oauth = OAuth(app) remote = oauth.remote_app( 'dev', consumer_key='dev', consumer_secret='dev', request_token_params={'scope': 'email'}, base_url='http://127.0.0.1:5000/api/', request_token_url=None, access_token_method='POST', access_token_url='http://127.0.0.1:5000/oauth/token', authorize_url='http://127.0.0.1:5000/oauth/authorize' ) client = app.extensions['oauthlib.client'] assert client.dev.name == 'dev'
def __init__(self, client_id, client_secret): super(GoogleSignIn, self).__init__(provider_name="google") oauth = OAuth() self.service = oauth.remote_app( 'google', consumer_key=client_id, consumer_secret=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', ) self.service.tokengetter(GoogleSignIn._get_token)
def __init__(self): super().__init__('google') oauth = OAuth() self.service = oauth.remote_app( 'google', consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['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', ) self.service.tokengetter(GoogleSignIn.get_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'
def __init__(self,app,oauth_name=None,oauth_key=None,oauth_secret=None,oauth_scope=None,oauth_access_token_url=None, oauth_authorize_url=None,oauth_request_token_url=None,oauth_base_api_url=None,oauth_callback_url=None, *args,**kwargs): super(NemoOauthPlugin, self).__init__(*args,**kwargs) oauth = OAuth(app) self.authobj = oauth.remote_app( oauth_name, consumer_key=oauth_key, consumer_secret=oauth_secret, request_token_params={'scope':oauth_scope}, base_url=oauth_base_api_url, request_token_url=oauth_request_token_url, access_token_method='POST', access_token_url=oauth_access_token_url, authorize_url=oauth_authorize_url ) self.authobj.tokengetter(self.oauth_token) self.authcallback = oauth_callback_url
def get_google( app ): oauth = OAuth(app) app.logger.debug( app.config.keys() ) google = oauth.remote_app( 'google', consumer_key=app.config.get('GOOGLE_ID'), consumer_secret=app.config.get('GOOGLE_SECRET'), request_token_params={ 'scope': ['profile', 'https://www.googleapis.com/auth/userinfo.email'], 'approval_prompt' : 'force', 'access_type':'offline' }, 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', ) return google
def create_oauth(app): oauth = OAuth(app) google = oauth.remote_app('google', consumer_key=GOOGLE_ID, consumer_secret=GOOGLE_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', ) @google.tokengetter def get_google_oauth_token(): return session.get('google_token') return google
from flask import Flask, url_for, session, request, jsonify from flask_oauthlib.client import OAuth CLIENT_ID = 'ybazvHasortLpoSvnbeoLQssh311isEfizKsCAs3' CLIENT_SECRET = 'kxrgkC07lp9XGoAq4l9JNJrDbuZ9CkfYdzwKvtxQB1JfMTo30V' app = Flask(__name__) app.debug = True app.secret_key = 'secret' oauth = OAuth(app) remote = oauth.remote_app( 'remote', consumer_key=CLIENT_ID, consumer_secret=CLIENT_SECRET, request_token_params={'scope': 'email'}, base_url='http://192.168.2.1:8080/api/', request_token_url=None, access_token_url='http://192.168.2.1:8080/oauth/token', authorize_url='http://192.168.2.1:8080/oauth/authorize') @app.route('/') def index(): if 'remote_oauth' in session: resp = remote.get('me') return jsonify(resp.data) next_url = request.args.get('next') or request.referrer or None return remote.authorize( callback=url_for('authorized', next=next_url, _external=True))
GOOGLE_DISCOVERY_URL = ( "https://accounts.google.com/.well-known/openid-configuration") facebook_credentials = app.config['OAUTH_CREDENTIALS']['facebook'] FACEBOOK_APP_ID = facebook_credentials['id'] FACEBOOK_APP_SECRET = facebook_credentials['secret'] SECRET_KEY = app.secret_key # OAuth 2 client setup google_client = WebApplicationClient(GOOGLE_CLIENT_ID) oauth = OAuth() 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_APP_ID, consumer_secret=FACEBOOK_APP_SECRET, request_token_params={'scope': 'email'}) # Helper method to get user URL def get_google_provider_cfg(): return requests.get(GOOGLE_DISCOVERY_URL).json() login_template = Blueprint('login', __name__, template_folder='../templates', static_folder='../static')
from angular_flask import app from flask_sqlalchemy import SQLAlchemy from flask_restless import APIManager from flask_oauthlib.client import OAuth db = SQLAlchemy(app) oauth = OAuth() etsy = oauth.remote_app( 'etsy', base_url='https://openapi.etsy.com/v2', request_token_url= 'https://openapi.etsy.com/v2/oauth/request_token?scope=profile_r%20email_r%20listings_r%20transactions_r%20transactions_w%20shops_rw%20', access_token_url='https://openapi.etsy.com/v2/oauth/access_token', authorize_url='https://etsy.com/oauth/signin', consumer_key='fvfa290fd1oj7mz3q9sz8de3', consumer_secret='mrxd5mxylm') t = {} t['request_token_url'] = 'https://api.twitter.com/oauth/request_token' t['access_token_url'] = 'https://api.twitter.com/oauth/access_token' t['authorize_url'] = 'https://api.twitter.com/oauth/authenticate' t['consumer_key'] = 'r5dp81cC7nk1Vkk6FwsBJICHf' t['consumer_secret'] = '58Rf705PdE8SuWolk5DxAptS6kHyfASB1TptLf5yZevHsGgaLu' twittero = oauth.remote_app( 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 = Flask(__name__) app.secret_key = os.environ.get('PYB_100D_APP_SECRET') or sys.exit( 'need secret app key') oauth = OAuth(app) # urllib.error.URLError: <urlopen error # [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)> ssl._create_default_https_context = ssl._create_unverified_context twitter = oauth.remote_app( 'twitter', consumer_key=os.environ.get('PYB_100D_TW_KEY') or sys.exit('need tw key'), consumer_secret=os.environ.get('PYB_100D_TW_SECRET') or sys.exit('need tw secret'), 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') @twitter.tokengetter def get_twitter_token(): if 'twitter_oauth' in session: resp = session['twitter_oauth'] return resp['oauth_token'], resp['oauth_token_secret'] @app.before_request def before_request():
from flask import Flask, request, redirect, url_for, flash, render_template from flask_oauthlib.client import OAuth app = Flask(__name__) app.config['DEBUG'] = True oauth = OAuth() mySession = None currentUser = None app.secret_key = 'development' 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', consumer_key='xRxFoWzorAAgN8C2KGEUvFDdH', consumer_secret='8PiaFxKpSHKYQNCpjd86Unwirlx5aW48Tn1YSB1a4q9Dx77EbI' ) # Obtener token para esta sesion @twitter.tokengetter def get_twitter_token(token=None): global mySession if mySession is not None: return mySession['oauth_token'], mySession['oauth_token_secret'] # Limpiar sesion anterior e incluir la nueva sesion @app.before_request
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
def init(app): oauth = OAuth(app) # enables the usage of 127.0.0.1:7221 over http for OAuth purposes. os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' twitch = oauth.remote_app( 'twitch', consumer_key=app.bot_config['webtwitchapi']['client_id'], consumer_secret=app.bot_config['webtwitchapi']['client_secret'], request_token_params={ 'scope': 'user_read', }, base_url='http://127.0.0.1:7221/kraken/', request_token_url=None, access_token_method='POST', access_token_url='https://id.twitch.tv/oauth2/token', authorize_url='https://id.twitch.tv/oauth2/authorize', ) @app.route('/login') def login(): callback_url = app.bot_config['webtwitchapi'][ 'redirect_uri'] if 'redirect_uri' in app.bot_config[ 'webtwitchapi'] else url_for('authorized', _external=True) state = request.args.get('n') or request.referrer or None return twitch.authorize( callback=callback_url, state=state, ) @app.route('/login/error') def login_error(): return render_template('login_error.html') @app.route('/login/authorized') def authorized(): try: resp = twitch.authorized_response() except OAuthException: log.exception('An exception was caught while authorizing') next_url = get_next_url(request, 'state') return redirect(next_url) except: log.exception('Unhandled exception while authorizing') return render_template('login_error.html') print(resp) if resp is None: if 'error' in request.args and 'error_description' in request.args: log.warn('Access denied: reason={}, error={}'.format( request.args['error'], request.args['error_description'])) next_url = get_next_url(request, 'state') return redirect(next_url) elif type(resp) is OAuthException: log.warn(resp.message) log.warn(resp.data) log.warn(resp.type) next_url = get_next_url(request, 'state') return redirect(next_url) session['twitch_token'] = (resp['access_token'], ) me = twitch.get('user') level = 100 with DBManager.create_session_scope() as db_session: db_user = db_session.query(User).filter_by( username=me.data['name'].lower()).one_or_none() if db_user: level = db_user.level session['user'] = { 'username': me.data['name'], 'username_raw': me.data['display_name'], 'level': level, } next_url = get_next_url(request, 'state') return redirect(next_url) def get_next_url(request, key='n'): next_url = request.args.get(key, '/') if next_url.startswith('//'): return '/' return next_url @app.route('/logout') def logout(): session.pop('twitch_token', None) session.pop('user', None) next_url = get_next_url(request) if next_url.startswith('/admin'): next_url = '/' return redirect(next_url) @twitch.tokengetter def get_twitch_oauth_token(): return session.get('twitch_token') def change_twitch_header(uri, headers, body): auth = headers.get('Authorization') if auth: auth = auth.replace('Bearer', 'OAuth') headers['Authorization'] = auth return uri, headers, body twitch.pre_request = change_twitch_header
consumer_key = '' consumer_secret = '' basedir = os.path.abspath(os.path.dirname(__file__)) app = Flask(__name__) # app.debug = True app.config.from_object(__name__) app.secret_key = os.urandom(24) oauth = OAuth(app) twitter = oauth.remote_app( 'twitter', consumer_key = consumer_key, consumer_secret = consumer_secret, 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' ) oauth.init_app(app) @app.before_request def before_reqeust(): g.screen_name = None g.logged_in = False if 'user_info' in session: g.screen_name = session['user_info']['screen_name'] def get_verified_count():
import os from flask_oauthlib.client import OAuth from flask import g oauth = OAuth() github = oauth.remote_app( 'github', consumer_key=os.environ.get('GITHUB_CLIENT_ID'), consumer_secret=os.environ.get('GITHUB_SECRET_KEY'), 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", ) @github.tokengetter def tokengetter(): if 'access_token' in g: return g.access_token
from flask import Flask, url_for, render_template, request, redirect, session from flask_oauthlib.client import OAuth import sqlite3 SECRET_KEY = 'development key' app = Flask(__name__) app.secret_key = SECRET_KEY oauth = OAuth() twitter = oauth.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/authorize', consumer_key='NKHMeDZvNkJjZZtdp3dKrH7RH', consumer_secret='B5tmJXiMnFpmsLpifsRQ8BjbUfjDU7CnPkxp32E2c1bNzuTncQ') @twitter.tokengetter def get_twitter_token(token=None): return session.get('twitter_token') @app.route('/') def index(): return render_template('index.html') @app.route('/login', methods=['GET', 'POST']) def login():
import os from dotenv import load_dotenv from flask import g from flask_oauthlib.client import OAuth load_dotenv() oauth = OAuth() github = oauth.remote_app( "github", consumer_key=os.getenv("GITHUB_CONSUMER_KEY"), consumer_secret=os.getenv("GITHUB_CONSUMER_SECRET"), 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", ) @github.tokengetter def get_github_token(): if "access_token" in g: return g.access_token
def create_client(app): oauth = OAuth(app) remote = oauth.remote_app( 'ok-server', # Server Name consumer_key='example-app', consumer_secret='example-secret', request_token_params={ 'scope': 'all', 'state': lambda: security.gen_salt(10) }, base_url=url + '/api/v3/', request_token_url=None, access_token_method='POST', access_token_url=url + '/oauth/token', authorize_url=url + '/oauth/authorize') # Real OK Server # remote = oauth.remote_app( # 'ok-server', # Server Name # consumer_key='example', # consumer_secret='fake-secret-get-the-real-one', # request_token_params={'scope': 'email', # 'state': lambda: security.gen_salt(10)}, # base_url='https://okpy.org/api/v3/', # request_token_url=None, # access_token_method='POST', # access_token_url='https://okpy.org/oauth/token', # authorize_url='https://okpy.org/oauth/authorize' # ) # def check_req(uri, headers, body): # """ Add access_token to the URL Request. """ # if 'access_token' not in uri and session.get('dev_token'): # params = {'access_token': session.get('dev_token')[0]} # url_parts = list(urllib.parse.urlparse(uri)) # query = dict(urllib.parse.parse_qsl(url_parts[4])) # query.update(params) # # url_parts[4] = urllib.parse.urlencode(query) # uri = urllib.parse.urlunparse(url_parts) # return uri, headers, body # remote.pre_request = check_req @app.route('/') def index(): if 'dev_token' in session: ret = remote.get('user', token=session['dev_token']) # User: ret.data['data']['email'] return jsonify(ret.data) return redirect(url_for('login')) @app.route('/login') def login(): return remote.authorize(callback=url_for('authorized', _external=True)) @app.route('/logout') def logout(): session.pop('dev_token', None) return redirect(url_for('index')) @app.route('/authorized') def authorized(): resp = remote.authorized_response() if resp is None: return 'Access denied: error=%s' % (request.args['error']) if isinstance(resp, dict) and 'access_token' in resp: session['dev_token'] = (resp['access_token'], '') return jsonify(resp) return str(resp) @app.route('/user') def client_method(): token = session['dev_token'][0] r = requests.get(url + '/api/v3/user/?access_token={}'.format(token)) r.raise_for_status() return jsonify(r.json()) @remote.tokengetter def get_oauth_token(): return session.get('dev_token') return remote
from flask_oauthlib.client import OAuth from flask_mail import Mail from kombu import Exchange, Queue from celery import Celery from elasticsearch import Elasticsearch from aleph import default_settings, archive from aleph.ext import get_init db = SQLAlchemy() migrate = Migrate() mail = Mail() celery = Celery('aleph') assets = Environment() oauth = OAuth() oauth_provider = oauth.remote_app('provider', app_key='OAUTH') def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) if config.get('TESTING'): app.config.from_envvar('ALEPH_TEST_SETTINGS', silent=True) else: app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD'))
import logging import json logger = logging.getLogger(__name__) auth = Blueprint('auth', __name__) # --------------------------- OAUTH SETUP --------------------------- oauth = OAuth(app) google_auth = oauth.remote_app( 'google', consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['GOOGLE_CLIENT_SECRET'], request_token_params={'scope': "email"}, base_url='https://www.googleapis.com/oauth2/v3/', 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') @google_auth.tokengetter def get_access_token(): return session.get('google_token') # --------------------------- HELPER FUNCTIONS --------------------------- def user_from_google_token(token):
from .rocket import User from . import config, app, data, rocket from flask import render_template, session, flash, redirect, url_for, request from flask_oauthlib.client import OAuth from hashlib import sha256 import requests oauth = OAuth() slack_oauth = oauth.remote_app( "slack", base_url="https://slack.com/api/", access_token_url="https://slack.com/api/oauth.access", authorize_url="https://slack.com/oauth/authorize", consumer_key=config["slack"]["oauth"]["client_id"], consumer_secret=config["slack"]["oauth"]["client_secret"], request_token_params={"scope": "chat:write:user"}, ) @slack_oauth.tokengetter def slack_tokengetter(): return session.get("slack_token") @app.route("/slack_oauth") def site_slack_oauth(): return slack_oauth.authorize(callback="https://dev.mita.me/slack_callback") @app.route("/slack_callback")
from flask_sqlalchemy import SQLAlchemy from flask_oauthlib.client import OAuth __author__ = 'jtomaszk' db = SQLAlchemy() oauth = OAuth() google = oauth.remote_app('google', app_key='GOOGLE', request_token_params={ 'scope': 'email' }, # base_url='https://www.googleapis.com/oauth2/v1/', base_url='https://www.googleapis.com/oauth2/', 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' )
import os import json from flask import Flask, redirect, url_for, session, request, jsonify, Markup from flask_oauthlib.client import OAuth from config import Config app = Flask(__name__) app.debug = True app.secret_key = 'development' oauth = OAuth(app) qq = oauth.remote_app( 'qq', consumer_key=Config.QQ_APP_ID, consumer_secret=Config.QQ_APP_KEY, base_url='https://graph.qq.com', request_token_url=None, request_token_params={'scope': 'get_user_info'}, access_token_url='/oauth2.0/token', authorize_url='/oauth2.0/authorize', ) def json_to_dict(x): '''OAuthResponse class can't parse the JSON data with content-type - text/html and because of a rubbish api, we can't just tell flask-oauthlib to treat it as json.''' if x.find(b'callback') > -1: # the rubbish api (https://graph.qq.com/oauth2.0/authorize) is handled here as special case pos_lb = x.find(b'{') pos_rb = x.find(b'}') x = x[pos_lb:pos_rb + 1]
"""Authorization token handling functions.""" from flask import session from flask_oauthlib.client import OAuth import f8a_jobs.defaults as configuration oauth = OAuth() github = oauth.remote_app( 'github', consumer_key=configuration.GITHUB_CONSUMER_KEY, consumer_secret=configuration.GITHUB_CONSUMER_SECRET, request_token_params={'scope': 'user:email,read:org'}, 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' ) @github.tokengetter def get_github_oauth_token(): """Return the authorization token to GitHub.""" return session.get('auth_token')
from flask_restful import Api from flask_sqlalchemy import SQLAlchemy from backend.config import EnvironmentConfig def format_url(endpoint): parts = "/".join([i for i in endpoint.split("/") if i]) return "/api/{}/{}/".format(EnvironmentConfig.API_VERSION, parts) db = SQLAlchemy() migrate = Migrate() oauth = OAuth() osm = oauth.remote_app("osm", app_key="OSM_OAUTH_SETTINGS") # Import all models so that they are registered with SQLAlchemy from backend.models.postgis import * # noqa def create_app(env=None): """ Bootstrap function to initialise the Flask app and config :return: Initialised Flask app """ app = Flask(__name__, ) # Load configuration options from environment app.config.from_object("backend.config.EnvironmentConfig")
import os from logging.handlers import RotatingFileHandler from flask import Flask from flask_cors import CORS from flask_migrate import Migrate from flask_oauthlib.client import OAuth from flask_restful import Api from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() migrate = Migrate() oauth = OAuth() osm = oauth.remote_app( 'osm', app_key='OSM_OAUTH_SETTINGS' ) # Import all models so that they are registered with SQLAlchemy from server.models.postgis import * # noqa def create_app(env=None): """ Bootstrap function to initialise the Flask app and config :return: Initialised Flask app """ app = Flask(__name__) if env is None: env = os.getenv('TM_ENV', 'Dev') # default to Dev if config environment var not set
client_credentials = json.load(fd) oauth_api_endpoint = os.getenv('ACCESS_TOKEN_URL', '') oauth_tokeninfo_endpoint = os.getenv('TOKENINFO_URL', '') if oauth_api_endpoint == '': logging.error("no OAuth Endpoint provided. Exiting ...") exit(1) auth = oauth.remote_app( 'auth', consumer_key=client_credentials['client_id'], consumer_secret=client_credentials['client_secret'], request_token_params={'scope': 'uid'}, base_url=oauth_api_endpoint, request_token_url=None, access_token_method='POST', access_token_url=oauth_api_endpoint + '/oauth2/' + 'access_token?realm=employees', authorize_url=oauth_api_endpoint + '/oauth2/' 'authorize?realm=employees' ) # AppConfig(app, configfile) # Flask-Appconfig is not necessary, but # highly recommend =) # https://github.com/mbr/flask-appconfig Bootstrap(app) # in a real app, these should be configured through Flask-Appconfig app.config['SECRET_KEY'] = 'devkey'
application.config['WTF_CSRF_SECRET_KEY'] = os.urandom(24) application.config['SECRET_KEY'] = os.urandom(24) login_manager = LoginManager() login_manager.init_app(application) logging.basicConfig(filename='test.log', level=logging.DEBUG) application.secret_key = 'development' oauth = OAuth(application) github = oauth.remote_app( name='github', consumer_key='a11a1bda412d928fb39a', consumer_secret='92b7cf30bc42c49d589a10372c3f9ff3bb310037', 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') @login_manager.user_loader def load_user(user_id): q = base.db_session.query(User).filter(User.id == user_id) user = q.first() if user is not None: user._authenticated = True return user
import flask from flask_login import LoginManager from flask_migrate import Migrate from flask_oauthlib.client import OAuth from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() login_manager = LoginManager() oauth = OAuth() slack_oauth = oauth.remote_app('slack', base_url='https://api.slack.com', request_token_url=None, access_token_url='https://slack.com/api/oauth.access', # noqa authorize_url='https://slack.com/oauth/authorize', # noqa app_key='SLACK', request_token_params=dict( scope='identity.basic' )) @slack_oauth.tokengetter def _get_slack_token(): return flask.session.get('slack_token'), '' def init_app(app): """ Initialize the external application dependencies
# coding: utf-8 import os from flask import session from flask_oauthlib.client import OAuth _oauth = OAuth() _flask_oauthlib_twitter = _oauth.remote_app('twitter', consumer_key = os.getenv('TWITTER_CONSUMER_KEY'), consumer_secret = os.getenv('TWITTER_CONSUMER_SECRET'), access_token_url='https://api.twitter.com/oauth/access_token', authorize_url='https://api.twitter.com/oauth/authorize', request_token_url='https://api.twitter.com/oauth/request_token', base_url='https://api.twitter.com/1.1/') twitter = _flask_oauthlib_twitter # https://flask-oauthlib.readthedocs.org/en/latest/client.html @twitter.tokengetter def get_twitter_token(): return session.get('user', {}).get('twitter_credentials') # https://flask-oauthlib.readthedocs.org/en/latest/client.html def log_session_in(): """ Save OAuth AT/ATS info into session. """ resp = twitter.authorized_response() at, ats = resp['oauth_token'], resp['oauth_token_secret'] session['user'] = {'twitter_credentials': (at, ats)}
# Edited by S. Adams for Designing Software for the Web to add comments and remove flash messaging app = Flask(__name__) app.debug = True #Change this to False for production app.secret_key = os.environ['SECRET_KEY'] #use SECRET_KEY to sign session cookies oauth = OAuth(app) # Set up GitHub as OAuth provider github = oauth.remote_app( 'github', consumer_key=os.environ['GITHUB_CLIENT_ID'], #your web apps "username" for OAuth consumer_secret=os.environ['GITHUB_CLIENT_SECRET'], # web apps "password" for 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', authorize_url='https://github.com/login/oauth/authorize' #URL for github's OAuth login ) #context processors run before templates are rendered and add variables to the template context #context processors must return a dictionary #this context processor adds the variable logged_in to the context for all temlates @app.context_processor def inject_logged_in(): return {"logged_in":('github_token' in session)} @app.route('/') def home():
def create_oauth_client(app, name, **kwargs): """Helper function to create a OAuth2 client to test an OAuth2 provider.""" blueprint = Blueprint('oauth2test', __name__, template_folder='templates') default = dict( consumer_key='confidential', consumer_secret='confidential', request_token_params={'scope': 'test:scope'}, request_token_url=None, access_token_method='POST', access_token_url='/oauth/token', authorize_url='/oauth/authorize', content_type='application/json', ) default.update(kwargs) oauth = OAuth(app) remote = oauth.remote_app(name, **default) @blueprint.route('/oauth2test/login') def login(): return remote.authorize(callback=url_for('oauth2test.authorized', _external=True)) @blueprint.route('/oauth2test/logout') def logout(): session.pop('confidential_token', None) return "logout" @blueprint.route('/oauth2test/authorized') @remote.authorized_handler def authorized(resp): if resp is None: return 'Access denied: error=%s' % ( request.args.get('error', "unknown") ) if isinstance(resp, dict) and 'access_token' in resp: session['confidential_token'] = (resp['access_token'], '') return jsonify(resp) return str(resp) def get_test(test_url): if 'confidential_token' not in session: abort(403) else: ret = remote.get(test_url) if ret.status != 200: return abort(ret.status) return ret.raw_data @blueprint.route('/oauth2test/test-ping') def test_ping(): return get_test(url_for("invenio_oauth2server.ping")) @blueprint.route('/oauth2test/test-info') def test_info(): return get_test(url_for('invenio_oauth2server.info')) @blueprint.route('/oauth2test/test-invalid') def test_invalid(): return get_test(url_for('invenio_oauth2server.invalid')) @remote.tokengetter def get_oauth_token(): return session.get('confidential_token') app.register_blueprint(blueprint) return remote
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.login import LoginManager from config import basedir from flask_oauthlib.client import OAuth app = Flask(__name__) app.config.from_object('config') db = SQLAlchemy(app) lm = LoginManager() lm.init_app(app) lm.login_view = 'login' lm.refresh_view = 'refresh' oauth = OAuth(app) twitter = oauth.remote_app( 'twitter', consumer_key='tqC2q3KhStpJ14H90BqNg', consumer_secret='c4uaYwUkpSYIvGUjCQAj80z8GcowPwtK896GN8BjM', 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', ) from app import views, models
from flask import Flask, redirect, url_for, session, request, jsonify from flask_oauthlib.client import OAuth app = Flask(__name__) app.debug = True app.secret_key = 'development' oauth = OAuth(app) github = oauth.remote_app( 'gitstars', consumer_key='6ce4569a00ce43c79fb2', consumer_secret='e073c7ddc205d5e6ea7ce36801bc5f2caa2a25c9', 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' ) @app.route('/') def index(): if 'github_token' in session: me = github.get('user') return jsonify(me.data) return redirect(url_for('login')) @app.route('/login')
from Driver import Driver import json import collections app = Flask(__name__) #app.debug = True app.secret_key = 'development' oauth = OAuth(app) my_dr_global = Driver() github = oauth.remote_app( 'github', consumer_key='9668bff6a6d0cf60d387', consumer_secret='1adfdb0718d49e1f33bb68376ef439658c5f947d', 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') def _decode_list(data): rv = [] for item in data: if isinstance(item, unicode): item = item.encode('utf-8') elif isinstance(item, list): item = _decode_list(item) elif isinstance(item, dict): item = _decode_dict(item)
from celery import Celery from py2neo import Graph from elasticsearch import Elasticsearch from aleph import default_settings, archive from aleph.ext import get_init log = logging.getLogger(__name__) db = SQLAlchemy() migrate = Migrate() mail = Mail() celery = Celery('aleph') assets = Environment() oauth = OAuth() oauth_provider = oauth.remote_app('provider', app_key='OAUTH') def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) if config.get('TESTING'): app.config.from_envvar('ALEPH_TEST_SETTINGS', silent=True) else: app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD'))
import urllib.parse import re from flask import Flask, redirect, url_for, session, jsonify, request from flask_oauthlib.client import OAuth, OAuthException from sqlalchemy import create_engine, MetaData app = Flask(__name__) from app import config oauth = OAuth(app) zeus = oauth.remote_app( 'zeus', consumer_key=app.config['OAUTH_KEY'], consumer_secret=app.config['OAUTH_SECRET'], request_token_params={}, base_url='https://adams.ugent.be/oauth/api/', access_token_method='POST', access_token_url='https://adams.ugent.be/oauth/oauth2/token/', authorize_url='https://adams.ugent.be/oauth/oauth2/authorize/') tab_engine = create_engine(app.config['TAB_DB_URL'], convert_unicode=True, pool_pre_ping=True) tab_metadata = MetaData(bind=tab_engine) tap_engine = create_engine(app.config['TAP_DB_URL'], convert_unicode=True, pool_pre_ping=True) tap_metadata = MetaData(bind=tap_engine)
import urllib2 from xml.dom import minidom from glassdoor import get app.debug = True app.secret_key = 'development' oauth = OAuth(app) #75ovm95gewyled #VZwnHKUuyCXNX0to linkedin = oauth.remote_app( 'linkedin', consumer_key='75ovm95gewyled', consumer_secret='VZwnHKUuyCXNX0to', request_token_params={ 'scope': 'r_basicprofile,r_fullprofile,r_emailaddress,r_contactinfo,r_network', 'state': 'RandomString', }, base_url='https://api.linkedin.com/v1/', request_token_url=None, access_token_method='POST', access_token_url='https://www.linkedin.com/uas/oauth2/accessToken', authorize_url='https://www.linkedin.com/uas/oauth2/authorization', ) @app.route('/') def index(): if 'linkedin_token' in session: me = linkedin.get('people/~:(first-name,last-name,headline,picture-url,public-profile-url,formatted-name,summary,skills,email-address,main-address,phone-numbers,industry)') # user=User(nickname="ahsan",email="*****@*****.**") # db.session.add(user)
GOOGLE_ID='180871412866-i8algb2ticev3q7kfb9k6m07pn3j0vvk.apps.googleusercontent.com' GOOGLE_SECRET='8ZH4qN1t2-7dsJmGHn3LfDWU' app.config['GOOGLE_ID'] = "180871412866-i8algb2ticev3q7kfb9k6m07pn3j0vvk.apps.googleusercontent.com" app.config['GOOGLE_SECRET'] = "8ZH4qN1t2-7dsJmGHn3LfDWU" app.debug = True app.secret_key = 'development' oauth = OAuth(app) google = oauth.remote_app( 'google', consumer_key=app.config.get('GOOGLE_ID'), consumer_secret=app.config.get('GOOGLE_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', ) #APP_ROOT = os.path.dirname(os.path.abspath(__file__)) @app.route("/") def index(): if 'role' in session: role=session['role'] if role=='admin':
from flask import Flask, redirect, url_for, session, request, jsonify from flask_oauthlib.client import OAuth app = Flask(__name__) app.debug = True app.secret_key = 'development' oauth = OAuth(app) linkedin = oauth.remote_app( 'linkedin', consumer_key='k8fhkgkkqzub', consumer_secret='ZZtLETQOQYNDjMrz', request_token_params={ 'scope': 'r_basicprofile', 'state': 'RandomString', }, base_url='https://api.linkedin.com/v1/', request_token_url=None, access_token_method='POST', access_token_url='https://www.linkedin.com/uas/oauth2/accessToken', authorize_url='https://www.linkedin.com/uas/oauth2/authorization', ) @app.route('/') def index(): if 'linkedin_token' in session: me = linkedin.get('people/~') return jsonify(me.data) return redirect(url_for('login'))
app.debug = False app.secret_key = os.environ['APP_SECRET_KEY'] oauth = OAuth(app) # This code originally from https://github.com/lepture/flask-oauthlib/blob/master/example/github.py # Edited by P. Conrad for SPIS 2016 to add getting Client Id and Secret from # environment variables, so that this will work on Heroku. github = oauth.remote_app( 'github', consumer_key=os.environ['GITHUB_CLIENT_ID'], consumer_secret=os.environ['GITHUB_CLIENT_SECRET'], request_token_params={'scope': 'read:org'}, 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' ) @app.context_processor def inject_logged_in(): return dict(logged_in=('github_token' in session)) @app.context_processor def inject_github_org(): return dict(github_org=os.getenv('GITHUB_ORG'))
from forms import EditUserForm, PostForm, SearchForm, EditPostForm from app import app, db, lm from models import User, Post from flask_oauthlib.client import OAuth from flask.ext.login import login_user, logout_user, current_user, login_required from flask.ext.misaka import markdown @lm.user_loader def load_user(id): return User.query.get(int(id)) oauth = OAuth() fb_oauth = 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=app.config['OAUTH_CREDENTIALS']['facebook']['id'], consumer_secret=app.config['OAUTH_CREDENTIALS']['facebook']['secret'], request_token_params={'scope': 'email, public_profile'}) tw_oauth = oauth.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/authorize', consumer_key=app.config['OAUTH_CREDENTIALS']['twitter']['id'], consumer_secret=app.config['OAUTH_CREDENTIALS']['twitter']['secret'] ) gg_oauth = oauth.remote_app('google', base_url='https://www.google.com/accounts/',
@APP.errorhandler(Exception) def handle_auth_error(ex): response = jsonify(message=ex.message) return response oauth = OAuth(APP) auth0 = oauth.remote_app( 'auth0', consumer_key=AUTH0_CLIENT_ID, consumer_secret=AUTH0_CLIENT_SECRET, request_token_params={ 'scope': 'openid profile', 'audience': AUTH0_AUDIENCE }, base_url='https://%s' % AUTH0_DOMAIN, access_token_method='POST', access_token_url='/oauth/token', authorize_url='/authorize', ) def requires_auth(f): @wraps(f) def decorated(*args, **kwargs): if constants.PROFILE_KEY not in session: return redirect('/login') return f(*args, **kwargs)