def get_github_oauth_client(self, site=None, scope='', token='github_oauth_token'): """Returns a instance of LinkedIn OAuth :param site: Browserecord of the website, If not specified, it will be guessed from the request context """ if site is None: site = request.nereid_website if not all([site.github_id, site.github_secret]): current_app.logger.error("Github api settings are missing") flash(_("Github login is not available at the moment")) return None oauth = OAuth() github = oauth.remote_app( 'github', base_url='https://github.com', request_token_url=None, access_token_url='/login/oauth/access_token', authorize_url='/login/oauth/authorize', consumer_key=site.github_id, consumer_secret=site.github_secret, request_token_params={'scope': scope}, access_token_method="POST", ) github.tokengetter_func = lambda *a: session.get(token) return github
def __init__(self, application_id, application_secret, dm_id): self.oauth = OAuth() self.connection = oauth.remote_app('facebook', base_url=Facebook.graphApiUrl, request_token_url=None, access_token_url='/oauth/access_token', authorize_url='https://www.facebook.com/dialog/oauth', consumer_key=application_id, consumer_secret=application_secret, request_token_params={'scope': 'email'}) self.dm_id = dm_id
class Twitter: oauth = OAuth() def __init__(self, c_k, c_s): #oauth = OAuth() # Use Twitter as example remote application self.oauth = self.oauth.remote_app( 'twitter', # unless absolute urls are used to make requests, this will be added # before all URLs. This is also true for request_token_url and others. base_url='http://api.twitter.com/1/', # where flask should look for new request tokens request_token_url='http://api.twitter.com/oauth/request_token', # where flask should exchange the token with the remote application access_token_url='http://api.twitter.com/oauth/access_token', # twitter knows two authorizatiom URLs. /authorize and /authenticate. # they mostly work the same, but for sign on /authenticate is # expected because this will give the user a slightly different # user interface on the twitter side. authorize_url='http://api.twitter.com/oauth/authenticate', # the consumer keys from the twitter application registry. consumer_key=c_k, #app.config['TWITTER_CONSUMER_KEY'], consumer_secret=c_s #app.config['TWITTER_CONSUMER_KEY'] )
__author__ = 'david' import urllib, json from flask import session from flaskext.oauth import OAuth oauth = OAuth() class Facebook(): graphApiUrl = 'https://graph.facebook.com/' def __init__(self, application_id, application_secret, dm_id): self.oauth = OAuth() self.connection = oauth.remote_app('facebook', base_url=Facebook.graphApiUrl, request_token_url=None, access_token_url='/oauth/access_token', authorize_url='https://www.facebook.com/dialog/oauth', consumer_key=application_id, consumer_secret=application_secret, request_token_params={'scope': 'email'}) self.dm_id = dm_id def authorize(self, resp): access_token = resp['access_token'] profile = self._get_profile(access_token) if profile["id"] == self.dm_id: session['dm'] = True elif self._is_player(access_token):
def init_app(self, app): if app is None: return blueprint = Blueprint('social', __name__) config = default_config.copy() try: config.update(app.config['SOCIAL']) except: pass app.config['SOCIAL'] = config # Update the service provider configurations social_providers_config = {} if 'SOCIAL_PROVIDERS' in app.config: for provider, provider_config in default_provider_config.items(): if provider in app.config['SOCIAL_PROVIDERS']: d_config = provider_config.copy() d_oauth_config = d_config['oauth'].copy() p_config = app.config['SOCIAL_PROVIDERS'][provider][ 'oauth'] d_config.update(app.config['SOCIAL_PROVIDERS'][provider]) d_oauth_config.update(p_config) d_config['oauth'] = d_oauth_config social_providers_config[provider] = d_config app.config['SOCIAL_PROVIDERS'] = social_providers_config app.logger.debug('Social Configuration: %s' % app.config['SOCIAL']) app.logger.debug('Social Provider Configuration: ' '%s' % app.config['SOCIAL_PROVIDERS']) # Connection service name app.oauth = OAuth() app.social = self @blueprint.route('/login/<provider_id>', methods=['POST']) def login(provider_id): if current_user.is_authenticated(): return redirect("/") callback_url = get_authorize_callback('/login/%s' % provider_id) current_app.logger.debug( 'Starting login via %s account. Callback ' 'URL = %s' % (get_display_name(provider_id), callback_url)) session['post_oauth_login_url'] = request.form.get( 'next', current_app.config['AUTH']['post_login_view']) remote_app = get_remote_app(provider_id).remote_app return remote_app.authorize(callback_url) @blueprint.route('/connect/<provider_id>', methods=['POST']) @login_required def connect(provider_id): callback_url = get_authorize_callback('/connect/%s' % provider_id) current_app.logger.debug( 'Starting process of connecting %s ' 'account to user account %s. Callback URL = %s' % (get_display_name(provider_id), current_user, callback_url)) session['post_oauth_connect_url'] = request.form.get( 'next', current_app.config['SOCIAL']['connect_allow_view']) remote_app = get_remote_app(provider_id).remote_app return remote_app.authorize(callback_url) @blueprint.route('/connect/<provider_id>', methods=['DELETE']) @login_required def remove_all_connections(provider_id): try: display_name = get_display_name(provider_id) connection_service.remove_all_connections( current_user.get_id(), provider_id) current_app.logger.debug('Removed all connections to %s for ' '%s' % (provider_id, current_user)) flash("Connections to %s removed" % display_name) except: current_app.logger.error( 'Unable to remove all connections to ' '%s for %s' % (get_display_name(provider_id), current_user)) flash("Unabled to remove connection") return redirect(request.referrer) @blueprint.route('/connect/<provider_id>/<provider_user_id>', methods=['DELETE']) @login_required def remove_connection(provider_id, provider_user_id): try: display_name = get_display_name(provider_id) connection_service.remove_connection(current_user.get_id(), provider_id, provider_user_id) current_app.logger.debug('Removed connection to %s for ' '%s' % (provider_id, current_user)) flash("Connection to %s removed" % display_name) except: current_app.logger.error( 'Unable to remove connection to %s/%s ' 'for %s' % (get_display_name(provider_id), provider_user_id, current_user)) flash("Unabled to remove connection") return redirect(request.referrer) # Setup handlers for the configured providers for p_id, p_config in app.config['SOCIAL_PROVIDERS'].items(): _configure_provider(app, blueprint, app.oauth, p_id, p_config) app.register_blueprint(blueprint, url_prefix=app.config['SOCIAL']['url_prefix'])
from flask import Module, render_template, request, redirect, url_for, session, flash, g from flaskext.oauth import OAuth from functools import wraps from crowdwoo import queries # define the remote oauth application twitter = OAuth().remote_app('twitter', base_url='http://api.twitter.com/1/', request_token_url='http://api.twitter.com/oauth/request_token', access_token_url='http://api.twitter.com/oauth/access_token', authorize_url='http://api.twitter.com/oauth/authenticate', consumer_key='foo', consumer_secret='bar' ) # define this module auth = Module(__name__) @auth.route('/signin') def signin(): return twitter.authorize(callback=url_for('oauth_authorized', next=request.args.get('next') or request.referrer or None)) @auth.route('/signout') def signout(): if 'user' in session: del(session['user']) return redirect(url_for('core.index'))
from dateutil import parser as date_parser from boto.s3.connection import S3Connection from flask import url_for, session, redirect, request, render_template from flaskext.oauth import OAuth from supportsomething import app from uuid import uuid4 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=app.config['FACEBOOK_APP_ID'], consumer_secret=app.config['FACEBOOK_APP_SECRET'], request_token_params={'scope': 'email'} ) conn = S3Connection(aws_access_key_id=app.config['AWS_ACCESS_KEY_ID'], aws_secret_access_key=app.config[ 'AWS_SECRET_ACCESS_KEY']) bucket = conn.get_bucket('support-something') @app.route('/') def index(): imgs = [] for key in bucket.list('imgs'): if key.name != 'imgs/': imgs.append(( 'https://support-something.s3.amazonaws.com/%s' % key.name,