def init_oauth(app): global o_twitter, o_facebook, oauth_authorized oauth = OAuth() o_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/authenticate', consumer_key=app.config["OAUTH_TWITTER_CONSUMER_KEY"], consumer_secret=app.config["OAUTH_TWITTER_CONSUMER_SECRET"], access_token_method='POST' ) user.add_url_rule('/oauth/twitter', "twitter_authorized", o_twitter.authorized_handler(twitter_authorized)) o_twitter.tokengetter(oauth_token) o_facebook = oauth.remote_app('facebook', base_url='https://graph.facebook.com/', request_token_url=None, access_token_url='/oauth/access_token', authorize_url=app.config["OAUTH_FACEBOOK_SITE_URL"], consumer_key=app.config["OAUTH_FACEBOOK_CONSUMER_KEY"], consumer_secret=app.config["OAUTH_FACEBOOK_CONSUMER_SECRET"], request_token_params={'scope': 'email'} ) user.add_url_rule('/oauth/facebook', "facebook_authorized", o_facebook.authorized_handler(facebook_authorized)) o_facebook.tokengetter(oauth_token)
def __init__(self, name, title, key, secret, access_key, access_secret, at_login=True, priority=True, icon=None): self.name = name self.title = title self.at_login = at_login self.priority = priority self.icon = icon self.consumer_key = key self.consumer_secret = secret self.access_key = access_key self.access_secret = access_secret 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/authenticate", consumer_key=key, consumer_secret=secret, ) twitter.tokengetter(lambda token=None: None) # We have no use for tokengetter self.callback = twitter_exception_handler(twitter.authorized_handler(self.unwrapped_callback)) self.twitter = twitter
def config_web(args): from flask import Flask from flask.ext.login import LoginManager from flask.ext.oauth import OAuth global app app = Flask('wikimetrics') web_config = create_object_from_text_config_file(args.web_config) app.config.from_object(web_config) if args.override_config: web_config = create_object_from_text_config_file(args.override_config) app.config.from_object(web_config) global login_manager login_manager = LoginManager() login_manager.init_app(app) global google oauth = OAuth() google = oauth.remote_app( 'google', base_url=app.config['GOOGLE_BASE_URL'], authorize_url=app.config['GOOGLE_AUTH_URI'], request_token_url=None, request_token_params={ 'scope': app.config['GOOGLE_AUTH_SCOPE'], 'response_type': 'code', }, access_token_url=app.config['GOOGLE_TOKEN_URI'], access_token_method='POST', access_token_params={'grant_type': 'authorization_code'}, consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['GOOGLE_CLIENT_SECRET'], )
def __init__(self, name, title, key, secret, access_key, access_secret, at_login=True, priority=True): self.name = name self.title = title self.at_login = at_login self.priority = priority self.consumer_key = key self.consumer_secret = secret self.access_key = access_key self.access_secret = access_secret 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/authenticate', consumer_key=key, consumer_secret=secret, ) twitter.tokengetter( lambda token=None: None) # We have no use for tokengetter self.callback = twitter_exception_handler( twitter.authorized_handler(self.unwrapped_callback)) self.twitter = twitter
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 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.tokengetter) return twitter
def get_github_oauth_client(self, scope='', token='github_oauth_token'): """Returns a instance of Github OAuth """ if not all([self.github_id, self.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=self.github_id, consumer_secret=self.github_secret, request_token_params={'scope': scope}, access_token_method="POST", ) github.tokengetter_func = lambda *a: session.get(token) return github
def config_web(args): from flask import Flask from flask.ext.login import LoginManager from flask.ext.oauth import OAuth global app app = Flask('wikimetrics') web_config = create_object_from_text_config_file(args.web_config) app.config.from_object(web_config) if args.override_config: web_config = create_object_from_text_config_file(args.override_config) app.config.from_object(web_config) global login_manager login_manager = LoginManager() login_manager.init_app(app) global google oauth = OAuth() google = oauth.remote_app( 'google', base_url=app.config['GOOGLE_BASE_URL'], authorize_url=app.config['GOOGLE_AUTH_URI'], request_token_url=None, request_token_params={ 'scope': app.config['GOOGLE_AUTH_SCOPE'], 'response_type': 'code', }, access_token_url=app.config['GOOGLE_TOKEN_URI'], access_token_method='POST', access_token_params={ 'grant_type': 'authorization_code' }, consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['GOOGLE_CLIENT_SECRET'], )
from mongoengine import connect import os FACEBOOK_APP_ID = "" FACEBOOK_APP_SECRET = "" TWITTER_APP_ID = "" TWITTER_APP_SECRET = "" #Defining Remote Applications 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', 'redirect_uri': 'https://crate.ly/#Dashboard', 'display': 'popup'} ) 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=TWITTER_APP_ID, consumer_secret=TWITTER_APP_SECRET )
app = Flask(__name__) # import config from $APP_CONFIG file app.config.from_envvar('APP_CONFIG') app.secret_key = app.config['SECRET_KEY'] # google oauth2 setup oauth = OAuth() google = oauth.remote_app('google', base_url='https://www.google.com/accounts/', authorize_url='https://accounts.google.com/o/oauth2/auth', request_token_url=None, request_token_params= {'scope': 'https://www.googleapis.com/auth/userinfo.email \ https://www.googleapis.com/auth/userinfo.profile http://www.google.com/reader/api/0/subscription/list', 'response_type': 'code'}, access_token_url='https://accounts.google.com/o/oauth2/token', access_token_method='POST', access_token_params={'grant_type': 'authorization_code'}, consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['GOOGLE_CLIENT_SECRET']) # login manager login_manager = LoginManager() login_manager.setup_app(app) login_manager.login_view = 'login' login_manager.anonymous_user = Anonymous @login_manager.user_loader def load_user(user_id): return User.load(user_id)
patch_psycopg() except: pass app = Flask(__name__) app.config.from_pyfile('config.py') csrf = SeaSurf(app) db = SQLAlchemy(app) login_manager = LoginManager() login_manager.setup_app(app) 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/authorize', consumer_key=app.config['TWITTER_CONSUMER_KEY'], consumer_secret=app.config['TWITTER_CONSUMER_SECRET']) from views import * if __name__ == '__main__': # Bind to PORT if defined, otherwise default to 5000. port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port)
# setup flask app = Flask(__name__) app.debug = DEBUG app.secret_key = SECRET_KEY oauth = OAuth() # Use Twitter as example remote application twitter = 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='xBeXxg9lyElUgwZT6AZ0A', consumer_secret='aawnSpNTOVuDCjx7HMh6uSXetjNN8zWLpZwCEU4LBrk') # setup sqlalchemy engine = create_engine(DATABASE_URI) db_session = scoped_session( sessionmaker(autocommit=False, autoflush=False, bind=engine)) Base = declarative_base() Base.query = db_session.query_property()
return app.config[key] elif key in os.environ: app.config[key] = os.environ[key] return app.config[key] return default app.secret_key = conf('FLASK_SECRET_KEY', 'Bn1dcC2QDWXgtj') app.config['BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT'] = conf('BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT') Bootstrap(app) oauth = OAuth() meetup_oauth = oauth.remote_app('meetup', base_url='https://api.meetup.com/', request_token_url='https://api.meetup.com/oauth/request/', access_token_url='https://api.meetup.com/oauth/access/', authorize_url='http://www.meetup.com/authorize/', consumer_key=conf('MEETUP_OAUTH_CONSUMER_KEY'), consumer_secret=conf('MEETUP_OAUTH_CONSUMER_SECRET'), ) meetup = Meetup(meetup_oauth) app.config['MONGO_URI'] = conf('MONGOHQ_URL', 'mongodb://localhost/meetups') mongo = PyMongo(app) sendgrid_api = sendgrid.Sendgrid( username=conf('SENDGRID_USERNAME'), password=conf('SENDGRID_PASSWORD'), secure=True, ) if conf('BUGSNAG_API_KEY'):
from flask.ext.oauth import OAuth, OAuthException # OAuth 1.0a from httplib import BadStatusLine from coaster import valid_username from coaster.views import get_next_url from lastuserapp import app from lastuserapp.models import db, UserExternalId, UserEmail, User from lastuserapp.views.helpers import login_internal, register_internal from lastuserapp.utils import get_gravatar_md5sum # OAuth 1.0a handlers 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/authenticate', consumer_key=app.config.get('OAUTH_TWITTER_KEY'), consumer_secret=app.config.get('OAUTH_TWITTER_SECRET'), ) def get_extid_token(service): useridinfo = session.get('userid_external') if useridinfo: if service != useridinfo.get('service'): return None extid = UserExternalId.query.filter_by(service=service, userid=useridinfo['userid']).first() if extid: return {'oauth_token': extid.oauth_token, 'oauth_token_secret': extid.oauth_token_secret} return None
app = Flask(__name__) # import config from $APP_CONFIG file app.config.from_envvar("APP_CONFIG") # export APP_CONFIG=/path/to/settings.cfg app.secret_key = app.config["SECRET_KEY"] oauth = OAuth() google = oauth.remote_app( "google", base_url="https://www.google.com/accounts/", authorize_url="https://accounts.google.com/o/oauth2/auth", request_token_url=None, request_token_params={ "scope": "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile http://www.google.com/reader/api/0/subscription/list", "response_type": "code", }, access_token_url="https://accounts.google.com/o/oauth2/token", access_token_method="POST", access_token_params={"grant_type": "authorization_code"}, consumer_key=app.config["GOOGLE_CLIENT_ID"], consumer_secret=app.config["GOOGLE_CLIENT_SECRET"], ) # twitter oauth2 setup 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/authenticate", consumer_key=app.config["TWITTER_CLIENT_ID"],
# Create logging if app.config.get('LOG_FILE') == True: import logging from logging import FileHandler file_handler = FileHandler('log.txt') file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) 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=app.config.get('FACEBOOK_APP_ID'), consumer_secret=app.config.get('FACEBOOK_APP_SECRET'), request_token_params={'scope': 'email'}) google = oauth.remote_app( 'google', base_url='https://www.google.com/accounts/', request_token_url=None, access_token_url='https://accounts.google.com/o/oauth2/token', authorize_url='https://accounts.google.com/o/oauth2/auth', consumer_key=app.config.get('GOOGLE_CLIENT_ID'), consumer_secret=app.config.get('GOOGLE_CLIENT_SECRET'), access_token_method='POST', request_token_params={ 'response_type': 'code',
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.oauth import OAuth from flask.ext.login import LoginManager from config import SECRET_KEY, SQLALCHEMY_DATABASE_URI, \ TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI app.secret_key = SECRET_KEY db = SQLAlchemy(app) oauth = OAuth() twitter = oauth.remote_app('twitter', base_url = 'http://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 = TWITTER_CONSUMER_KEY, consumer_secret = TWITTER_CONSUMER_SECRET ) login_manager = LoginManager() login_manager.init_app(app) from app import views
from forms import SignupForm, LoginForm, PasswordResetForm, PasswordChangeForm, DetailForm from flaskcamel import app, db from models import Users, UserDetail from decorators import async oauth = OAuth() toolbar = DebugToolbarExtension(app) bcrypt = Bcrypt() mail = Mail(app) # Faceboook App Credentials 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="your_consumer_key", consumer_secret="your_secret_key", request_token_params={"scope": "email"}, ) class Anonymous(AnonymousUser): name = u"Anonymous" login_manager = LoginManager() login_manager.anonymous_user = Anonymous login_manager.login_view = "login" login_manager.login_message = u"Please log in to access this page." login_manager.refresh_view = "reauth"
from allangles.middleware import MethodRewriteMiddleware app = Flask(__name__) app.config.from_object('allangles.configuration') app.wsgi_app = MethodRewriteMiddleware(app.wsgi_app) oauth = OAuth() db = SQLAlchemy(app) login_manager = LoginManager() login_manager.anonymous_user = AnonymousUser login_manager.login_view = 'login' login_manager.login_message = u'Please log in to access this page' @login_manager.user_loader def load_user(id): from allangles.models import User return User.query.filter_by(id=id).first() login_manager.setup_app(app) 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=os.environ.get('FB_API_KEY'), consumer_secret=os.environ.get('FB_SECRET'), request_token_params={'scope': 'email'} ) import allangles.views
from flask import session from flask.ext.oauth import OAuth from datawire.core import app oauth = OAuth() twitter = oauth.remote_app('twitter', base_url='https://api.twitter.com/1.1/', authorize_url='https://api.twitter.com/oauth/authorize', request_token_url='https://api.twitter.com/oauth/request_token', access_token_url='https://api.twitter.com/oauth/access_token', consumer_key=app.config.get('TWITTER_CONSUMER_KEY'), consumer_secret=app.config.get('TWITTER_CONSUMER_SECRET')) 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.get('FACEBOOK_APP_ID'), consumer_secret=app.config.get('FACEBOOK_APP_SECRET'), request_token_params={'scope': 'email'}) @twitter.tokengetter def get_twitter_token(token=None): return session.get('twitter_token') @facebook.tokengetter
return app.config[key] return default app.secret_key = conf('FLASK_SECRET_KEY', 'Bn1dcC2QDWXgtj') app.config['BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT'] = conf( 'BOOTSTRAP_GOOGLE_ANALYTICS_ACCOUNT') Bootstrap(app) oauth = OAuth() meetup_oauth = oauth.remote_app( 'meetup', base_url='https://api.meetup.com/', request_token_url='https://api.meetup.com/oauth/request/', access_token_url='https://api.meetup.com/oauth/access/', authorize_url='http://www.meetup.com/authorize/', consumer_key=conf('MEETUP_OAUTH_CONSUMER_KEY'), consumer_secret=conf('MEETUP_OAUTH_CONSUMER_SECRET'), ) meetup = Meetup(meetup_oauth) app.config['MONGO_URI'] = conf('MONGOHQ_URL', 'mongodb://localhost/meetups') mongo = PyMongo(app) sendgrid_api = sendgrid.Sendgrid( username=conf('SENDGRID_USERNAME'), password=conf('SENDGRID_PASSWORD'), secure=True, )
app = Flask(__name__) app.config.from_pyfile('config.py') csrf = SeaSurf(app) db = SQLAlchemy(app) login_manager = LoginManager() login_manager.setup_app(app) 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/authorize', consumer_key=app.config['TWITTER_CONSUMER_KEY'], consumer_secret=app.config['TWITTER_CONSUMER_SECRET'] ) class User(db.Model): id = db.Column(db.Integer, primary_key=True, nullable=False) name = db.Column(db.String(24), unique=True, nullable=False) oauth_token = db.Column(db.String(200), nullable=False) oauth_secret = db.Column(db.String(200), nullable=False) def get_id(self): return self.id
from flask import Flask, url_for, session, redirect, render_template, request, jsonify from flask.ext.oauth import OAuth from app import app from app import db, models app.secret_key = 'my secret-key-!@#$' oauth = OAuth() trello = oauth.remote_app( 'trello', base_url='', request_token_url='https://trello.com/1/OAuthGetRequestToken', access_token_url='https://trello.com/1/OAuthGetAccessToken', authorize_url='https://trello.com/1/OAuthAuthorizeToken', consumer_key='0c967eff30367539f04c711d283aba53', consumer_secret= '0a5ad962770bc02019b8f0737c5cb429760e5dadc25236e47067d45db3c1d162') @trello.tokengetter def token_getter(token=None): return session.get('token') @app.route('/') def index(): return trello.authorize(callback=url_for('authorized')) @app.route('/authorized/') @trello.authorized_handler
from flask import Module from flask import redirect, request, session, url_for from flask.ext.oauth import OAuth from db import Database from util import * login = Module(__name__) 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=os.environ['FACEBOOK_APP_ID'], consumer_secret=os.environ['FACEBOOK_APP_SECRET'], request_token_params={ 'scope': 'email,user_likes,friends_likes,user_location' }) def cookieUser(email, extra_data=None): if extra_data is None: extra_data = dict() userObjData = {'email': email} userObjData.update(extra_data) def saveAndSet(_userObj): Database.users.save(_userObj)
url_for('default.close_redirect', next_url=next_url)) ### # Twitter # Use Twitter as example remote application oauth = OAuth() twitter = 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='https://api.twitter.com/1/', # where flask should look for new request tokens request_token_url='https://api.twitter.com/oauth/request_token', # where flask should exchange the token with the remote application access_token_url='https://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='https://api.twitter.com/oauth/authenticate', # the consumer keys from the twitter application registry. consumer_key=config.TWITTER_CONSUMER_KEY, consumer_secret=config.TWITTER_CONSUMER_SECRET ) @twitter.tokengetter def get_twitter_token(): """This is used by the API to look for the auth token and secret it should use for API calls. During the authorization handshake a temporary set of token and secret is used, but afterwards this
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.oauth import OAuth from flask.ext.assets import Environment import certifi from celery import Celery from nomenklatura import default_settings logging.basicConfig(level=logging.DEBUG) app = Flask(__name__) app.config.from_object(default_settings) app.config.from_envvar('NOMENKLATURA_SETTINGS', silent=True) db = SQLAlchemy(app) assets = Environment(app) celery = Celery('nomenklatura', broker=app.config['CELERY_BROKER_URL']) oauth = OAuth() github = oauth.remote_app( 'github', base_url='https://github.com/login/oauth/', authorize_url='https://github.com/login/oauth/authorize', request_token_url=None, access_token_url='https://github.com/login/oauth/access_token', consumer_key=app.config.get('GITHUB_CLIENT_ID'), consumer_secret=app.config.get('GITHUB_CLIENT_SECRET')) github._client.ca_certs = certifi.where()
def config_web(args): from flask import Flask, request, json from flask.ext.login import LoginManager from flask.ext.oauth import ( OAuth, OAuthRemoteApp, OAuthException, get_etree ) from werkzeug import url_decode, parse_options_header import flask.ext.oauth as nasty_patch_to_oauth global app app = Flask('wikimetrics') # note absolute_path does not change on the life of the application app.absolute_path_to_app_root = get_absolute_path() # TODO do we need this config to be created like an object instead of a dictionary? web_config = create_object_from_text_config_file(args.web_config) # if args.override_config: # override_config = create_object_from_text_config_file(args.override_config) # TODO override one obj with other, can we use dict? app.config.from_object(web_config) version, latest = get_wikimetrics_version() app.config['WIKIMETRICS_LATEST'] = latest app.config['WIKIMETRICS_VERSION'] = version # configure logging if not app.config['DEBUG']: import logging import sys app.logger.addHandler(logging.StreamHandler(stream=sys.stderr)) global login_manager login_manager = LoginManager() login_manager.init_app(app) # TODO, this does not need to be a # global, could be stored in flask application context global google oauth = OAuth() google = oauth.remote_app( 'google', base_url=app.config['GOOGLE_BASE_URL'], authorize_url=app.config['GOOGLE_AUTH_URI'], request_token_url=None, request_token_params={ 'scope': app.config['GOOGLE_AUTH_SCOPE'], 'response_type': 'code', }, access_token_url=app.config['GOOGLE_TOKEN_URI'], access_token_method='POST', access_token_params={ 'grant_type': 'authorization_code' }, consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['GOOGLE_CLIENT_SECRET'], ) global mw_oauth_token mw_oauth_token = ConsumerToken( app.config['META_MW_CONSUMER_KEY'], app.config['META_MW_CLIENT_SECRET'], )
user = User.query.filter_by(username=username).first() if user is None: user = User(username=username) db.session.add(user) db.session.commit() # Log the user in here return redirect(url_for('blog.home')) 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='446037675585555', consumer_secret='2dff74777b42d680c268f4f6d2e10e44', request_token_params={'scope': 'email'}) @facebook.tokengetter def get_facebook_oauth_token(): return session.get('facebook_oauth_token') twitter = oauth.remote_app( 'twitter', base_url='https://api.twitter.com/1/', request_token_url='https://api.twitter.com/oauth/request_token',
# Create logging if app.config.get('LOG_FILE') == True: import logging from logging import FileHandler file_handler = FileHandler('log.txt') file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) 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=app.config.get('FACEBOOK_APP_ID'), consumer_secret=app.config.get('FACEBOOK_APP_SECRET'), request_token_params={'scope': 'email'} ) google = oauth.remote_app('google', base_url='https://www.google.com/accounts/', request_token_url=None, access_token_url='https://accounts.google.com/o/oauth2/token', authorize_url='https://accounts.google.com/o/oauth2/auth', consumer_key=app.config.get('GOOGLE_CLIENT_ID'), consumer_secret=app.config.get('GOOGLE_CLIENT_SECRET'), access_token_method='POST', request_token_params={'response_type':'code','scope':'https://www.googleapis.com/auth/userinfo.email'}, access_token_params={'grant_type':'authorization_code'} )
def __init__(self, code): self.code = code def init_db(): Base.metadata.create_all(bind=engine) def drop_db(): Base.metadata.drop_all(bind=engine) oauth = OAuth() vk = oauth.remote_app('vkontakte', base_url='https://api.vk.com/method/', request_token_url=None, access_token_url='https://api.vk.com/oauth/token', authorize_url='http://api.vk.com/oauth/authorize', consumer_key='2904906', consumer_secret='xpyuJye6NozdTazuuRvM', request_token_params={'scope': 'offline'} ) @app.before_request def before_request(): g.code=getattr(g,'code',None) if not g.code: g.code = sess.query(Acode).order_by(desc('date_created')).first() if not 'oauth_token' in session: session['oauth_token']=(g.code.code, '') @app.route('/') def hello():
return TaskBase.__call__(self, *args, **kwargs) celery.Task = ContextTask return celery celery = init_celery(app) oauth = OAuth() google = oauth.remote_app( 'google', base_url='https://www.google.com/accounts/', authorize_url='https://accounts.google.com/o/oauth2/auth', request_token_url=None, request_token_params={ 'scope': 'https://www.googleapis.com/auth/userinfo.email', 'response_type': 'code' }, access_token_url='https://accounts.google.com/o/oauth2/token', access_token_method='POST', access_token_params={'grant_type': 'authorization_code'}, consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['GOOGLE_CLIENT_SECRET']) import models import views @app.before_request def before_request(): g.db = db
def config_web(args): from flask import Flask, request, json from flask.ext.login import LoginManager from flask.ext.oauth import ( OAuth, OAuthRemoteApp, OAuthException, get_etree ) from werkzeug import url_decode, parse_options_header import flask.ext.oauth as nasty_patch_to_oauth global app app = Flask('wikimetrics') # note absolute_path does not change on the life of the application app.absolute_path_to_app_root = get_absolute_path() # TODO do we need this config to be created like an object instead of a dictionary? web_config = create_object_from_text_config_file(args.web_config) # if args.override_config: # override_config = create_object_from_text_config_file(args.override_config) # TODO override one obj with other, can we use dict? app.config.from_object(web_config) version, latest = get_wikimetrics_version() app.config['WIKIMETRICS_LATEST'] = latest app.config['WIKIMETRICS_VERSION'] = version # configure logging if not app.config['DEBUG']: import logging import sys app.logger.addHandler(logging.StreamHandler(stream=sys.stderr)) global login_manager login_manager = LoginManager() login_manager.init_app(app) # TODO, this does not need to be a # global, could be stored in flask application context global google oauth = OAuth() google = oauth.remote_app( 'google', base_url=app.config['GOOGLE_BASE_URL'], authorize_url=app.config['GOOGLE_AUTH_URI'], request_token_url=None, request_token_params={ 'scope': app.config['GOOGLE_AUTH_SCOPE'], 'response_type': 'code', }, access_token_url=app.config['GOOGLE_TOKEN_URI'], access_token_method='POST', access_token_params={ 'grant_type': 'authorization_code' }, consumer_key=app.config['GOOGLE_CLIENT_ID'], consumer_secret=app.config['GOOGLE_CLIENT_SECRET'], ) def better_parse_response(resp, content, strict=False): ct, options = parse_options_header(resp['content-type']) if ct in ('application/json', 'text/javascript'): try: return json.loads(content) # handle json decode errors from parse_response # this is useful in the identify call because the response is # 'application/json' but the content is encoded except: return content elif ct in ('application/xml', 'text/xml'): # technically, text/xml is ascii based but because many # implementations get that wrong and utf-8 is a superset # of utf-8 anyways, so there is not much harm in assuming # utf-8 here charset = options.get('charset', 'utf-8') return get_etree().fromstring(content.decode(charset)) elif ct != 'application/x-www-form-urlencoded': if strict: return content charset = options.get('charset', 'utf-8') return url_decode(content, charset=charset).to_dict() # TODO: Even worse, definitely patch upstream or consider switching to rauth nasty_patch_to_oauth.parse_response = better_parse_response # TODO: patch upstream # NOTE: a million thanks to Merlijn_van_Deen, author of # https://wikitech.wikimedia.org/wiki/Setting_up_Flask_cgi_app_as_a_tool/OAuth class MediaWikiOAuthRemoteApp(OAuthRemoteApp): def handle_oauth1_response(self): """ Handles an oauth1 authorization response. The return value of this method is forwarded as the first argument to the handling view function. """ client = self.make_client() resp, content = client.request( '{0}&oauth_verifier={1}'.format( self.expand_url(self.access_token_url), request.args['oauth_verifier'], ), self.access_token_method ) data = nasty_patch_to_oauth.parse_response(resp, content) if not self.status_okay(resp): raise OAuthException( 'Invalid response from ' + self.name, type='invalid_response', data=data ) return data global meta_mw meta_mw_base_url = app.config['META_MW_BASE_URL'] meta_mw = MediaWikiOAuthRemoteApp( oauth, 'meta_mw', base_url=meta_mw_base_url, request_token_url=meta_mw_base_url + app.config['META_MW_BASE_INDEX'], request_token_params={ 'title': 'Special:MWOAuth/initiate', 'oauth_callback': 'oob' }, access_token_url=meta_mw_base_url + app.config['META_MW_TOKEN_URI'], authorize_url=meta_mw_base_url + app.config['META_MW_AUTH_URI'], consumer_key=app.config['META_MW_CONSUMER_KEY'], consumer_secret=app.config['META_MW_CLIENT_SECRET'], ) oauth.remote_apps['meta_mw'] = meta_mw
from flask.ext.oauth import OAuth import config import bleach import markdown app = Flask("index") app.config.from_object(config) app.secret_key = config.SECRET mongo = PyMongo(app) oauth = OAuth() twitter = oauth.remote_app( 'KittyCheck', consumer_key=config.TWITTER["consumer_key"], consumer_secret=config.TWITTER["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/authenticate', ) def jsonify(hash, callback=None): if hash.has_key('_id'): del hash['_id'] res = simplejson.dumps(hash, ensure_ascii=False) if callback: res = callback + '(' + res + ');' return Response(res, mimetype='text/javascript')
circular dependency here. Import 'Account' after 'db' to temporarily resolve this. """ from models import Account ########################### 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 = settings.FACEBOOK_APP_ID, consumer_secret = settings.FACEBOOK_APP_SECRET, request_token_params = { 'scope': settings.FACEBOOK_APP_SCOPE } ) ########################### login_manager = LoginManager() @login_manager.user_loader def load_user(userid): return Account.query.filter_by(id=userid).first()
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.oauth import OAuth from juggernaut import Juggernaut app = Flask(__name__) app.config.from_pyfile('config.cfg') db = SQLAlchemy(app) oauth = OAuth() jug = Juggernaut() 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='188477911223606', consumer_secret='621413ddea2bcc5b2e83d42fc40495de', request_token_params={'scope': 'email'} ) def url_for_other_page(page): args = request.view_args.copy() args['page'] = page return url_for(request.endpoint, **args) app.jinja_env.globals['url_for_other_page'] = url_for_other_page class Paste(db.Model): id = db.Column(db.Integer, primary_key=True)
from flask import Module from flask import redirect, request, session, url_for from flask.ext.oauth import OAuth from db import Database from util import * login = Module(__name__) 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="178485798938752", consumer_secret="3fc3c9f171bbb5221403307113662fe5", request_token_params={ 'scope': 'email,user_likes,friends_likes,user_location' }) def cookieUser(email, extra_data=None): if extra_data is None: extra_data = dict() userObjData = {'email': email} userObjData.update(extra_data) def saveAndSet(_userObj): Database.users.save(_userObj)
SECRET_KEY = 'development key' DEBUG = True FACEBOOK_APP_ID = '188477911223606' FACEBOOK_APP_SECRET = '621413ddea2bcc5b2e83d42fc40495de' app = Flask(__name__) app.debug = DEBUG app.secret_key = SECRET_KEY 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'}) @app.route('/') def index(): return redirect(url_for('login')) @app.route('/login') def login(): return facebook.authorize(callback=url_for('facebook_authorized', next=request.args.get('next')
from flask.ext.oauth import OAuth from sqlalchemy.orm import aliased, contains_eager from datetime import datetime from wtforms import Form 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='233700133415330', consumer_secret='1d28dccf888bb41517693847b1d335d8', request_token_params={'scope': 'email'} ) toolbar = DebugToolbarExtension(app) bcrypt = Bcrypt() mail = Mail(app) class Anonymous(AnonymousUserMixin): name = u"Anonymous" login_manager = LoginManager()
from ..service import user as user_service from ..service import donate as donate_service from flask_user import current_user, login_required, roles_required from ..helpers import allowed_file from ..models import db, BaseNameMixin, BaseMixin from ..mailer import Mailer mailer = Mailer() # Facebook requirements oauth = OAuth() facebook = oauth.remote_app( 'facebook', request_token_url=None, base_url='https://graph.facebook.com/', access_token_url='/oauth/access_token', authorize_url='https://www.facebook.com/dialog/oauth', consumer_key=app.config.get('FACEBOOK_CONSUMER_KEY'), consumer_secret=app.config.get('FACEBOOK_CONSUMER_SECRET'), request_token_params={'scope': 'email'}) @facebook.tokengetter def get_facebook_token(): return session.get('facebook_token') def pop_login_session(): session.pop('logged_in', None) session.pop('facebook_token', None) session.pop('email', None) @app.route('/campaign/success')
# -*- coding: utf-8 -*- from flask import Blueprint, flash, g, redirect, render_template, request, session, url_for from flask.ext.oauth import OAuth from app import db from .forms import LoginForm, RegistrationForm from .model import User import controller oauth = OAuth() oauth_twitter = oauth.remote_app('twitter', base_url = 'http://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', #authorize_url = 'https://api.twitter.com/oauth/authorize', consumer_key = '<CONSUMER_KEY>', consumer_secret = '<CONSUMER_SECRET>' ) MODULE_NAME = 'users' MODULE_PREFIX = '/user' module = Blueprint(MODULE_NAME, __name__, url_prefix=MODULE_PREFIX)
#!/usr/bin/env python # -*- coding: utf-8 -*- from flask.ext.seasurf import SeaSurf from flask.ext.oauth import OAuth from vksunshine.config import VK_BASE_URL, VK_ACCESS_TOKEN_URL, VK_AUTHORIZE_URL, \ VK_REQUEST_TOKEN_PARAMS, VK_CONSUMER_KEY, VK_CONSUMER_SECRET __all__ = ['csrf', 'oauth_manager', 'vkontakte'] csrf = SeaSurf() oauth_manager = OAuth() vkontakte = oauth_manager.remote_app('vkontakte', base_url=VK_BASE_URL, authorize_url=VK_AUTHORIZE_URL, request_token_url=None, request_token_params=VK_REQUEST_TOKEN_PARAMS, access_token_url=VK_ACCESS_TOKEN_URL, consumer_key=VK_CONSUMER_KEY, consumer_secret=VK_CONSUMER_SECRET)
for ix in INDEXES: try: ix.create(db.engine) except Exception, e: #print e pass 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=app.config["FACEBOOK_APP_ID"], consumer_secret=app.config["FACEBOOK_APP_SECRET"], request_token_params={'scope': 'email'} ) _old_render = render_template USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19" @celery.task(name="MovieFinder.GetRottenTomatoesScore", rate_limit="1/s", default_retry_delay=100) def GetRottenTomatoesScore(imdb_id): with celery.flask_app.test_request_context(): return _GetRottenTomatoesScore(imdb_id)
from flask.ext.oauth import OAuth import config import messages from database import db, Facebook as DBFacebook from user import get_current_user from post import Post oauth = OAuth() facebook = oauth.remote_app( name='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=config.get('facebook_app_id'), consumer_secret=config.get('facebook_app_secret'), request_token_params={'scope': 'publish_stream'} ) @login_required def authorization(): return facebook.authorize(callback=url_for('facebook_authorized', next=request.args.get('next') or url_for('index'), _external=True)) @facebook.authorized_handler @login_required def authorized(response):
from flask import Module from flask import redirect,request,session,url_for from flask.ext.oauth import OAuth from db import Database from util import * login = Module(__name__) 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="178485798938752", consumer_secret="3fc3c9f171bbb5221403307113662fe5", request_token_params={'scope': 'email,user_likes,friends_likes,user_location'} ) def cookieUser(email,extra_data=None): if extra_data is None: extra_data = dict() userObjData = { 'email': email } userObjData.update(extra_data) def saveAndSet(_userObj): Database.users.save(_userObj) _userObj['_id'] = str(_userObj['_id'])
#imports from flask import Flask from flask.ext.oauth import OAuth from config import * __author__ = 'ferron' app = Flask(__name__) app.secret_key = SECRET_KEY oauth = OAuth() carepass = oauth.remote_app('carepass', base_url=BASE_URL, authorize_url=OAUTH_ENDPOINT+'/authorize', request_token_url=None, request_token_params={'scope': SCOPE, 'response_type': 'code'}, access_token_url=OAUTH_ENDPOINT + '/token', access_token_method='POST', access_token_params={'grant_type': 'authorization_code'}, consumer_key=CLIENT_ID, consumer_secret=CLIENT_SECRET)
oauth = OAuth() babel = Babel(app) db.init_app(app) gravatar = Gravatar(app, size=100, rating='g', default='retro', force_default=False, force_lower=False) 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='160705233955349', consumer_secret='4f4fa3aedb2cba7a35267cba7bd3a883', ) 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='h2H3rxB5DogKqj9XpJ7Q', consumer_secret='FjBx1RI0HsRTev3m8FKPigcejMszFlSoEWGmVz75U' ) #########################################Templates###################################################### @app.template_filter()
from flask import Flask, url_for, session, redirect, render_template, request,jsonify from flask.ext.oauth import OAuth from app import app from app import db, models app.secret_key = 'my secret-key-!@#$' oauth = OAuth() trello = oauth.remote_app('trello', base_url='', request_token_url='https://trello.com/1/OAuthGetRequestToken', access_token_url='https://trello.com/1/OAuthGetAccessToken', authorize_url='https://trello.com/1/OAuthAuthorizeToken', consumer_key='0c967eff30367539f04c711d283aba53', consumer_secret='0a5ad962770bc02019b8f0737c5cb429760e5dadc25236e47067d45db3c1d162') @trello.tokengetter def token_getter(token=None): return session.get('token') @app.route('/') def index(): return trello.authorize(callback=url_for('authorized')) @app.route('/authorized/') @trello.authorized_handler def authorized(resp): session['token'] = ( resp['oauth_token'],
# setup flask app = Flask(__name__) app.debug = DEBUG app.secret_key = SECRET_KEY oauth = OAuth() # Use Twitter as example remote application twitter = 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='xBeXxg9lyElUgwZT6AZ0A', consumer_secret='aawnSpNTOVuDCjx7HMh6uSXetjNN8zWLpZwCEU4LBrk' ) # setup sqlalchemy engine = create_engine(DATABASE_URI) db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) Base = declarative_base()
from flask.ext.oauth import OAuth import config import bleach import markdown app = Flask("index") app.config.from_object(config) app.secret_key = config.SECRET mongo = PyMongo(app) oauth = OAuth() twitter = oauth.remote_app('KittyCheck', consumer_key=config.TWITTER["consumer_key"], consumer_secret=config.TWITTER["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/authenticate', ) def jsonify(hash, callback = None): if hash.has_key('_id'): del hash['_id'] res = simplejson.dumps(hash, ensure_ascii=False) if callback: res = callback + '(' + res + ');' return Response( res, mimetype='text/javascript' )