from flask_login import logout_user, confirm_login, LoginManager from nocache import nocache '''Application file where we register blueprints for all parts and add google api for login''' GOOGLE_CLIENT_ID = '968468250852-0hgdrduaga14on3nqo72mhhi0aovspel.apps.googleusercontent.com' GOOGLE_CLIENT_SECRET = 'AowoVK79d8yLqWt7M-5cy3mJ' REDIRECT_URI = '/oauth2callback' # one of the Redirect URIs from Google APIs console SECRET_KEY = 'development key' DEBUG = True from app import app, cursor, db app = Flask(__name__) app.debug = DEBUG app.secret_key = SECRET_KEY oauth = OAuth() login_manager = LoginManager() login_manager.init_app(app) # cache.init_app(app) login_manager.login_view = 'login' from application import application app.register_blueprint(application, url_prefix='/application') from application_part2 import application_part2 app.register_blueprint(application_part2, url_prefix='/application') from application_part3 import application_part3 app.register_blueprint(application_part3, url_prefix='/application') from application_part4 import application_part4
render_template from flask.ext.classy import FlaskView, route from flask.ext.login import LoginManager, login_user, logout_user, current_user, login_required from forms import * from models import * from crowdkastapp.authentication import authentication from crowdkastapp import application import md5, os from flask_oauth import OAuth from flask_oauthlib.client import OAuth from generate_token import generate_confirmation_token, confirm_token import datetime from crowdkastapp.email import send_email oauth = OAuth(application) twitter = oauth.remote_app( 'twitter', consumer_key=application.config['CONSUMER_KEY'], consumer_secret=application.config['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', ) @twitter.tokengetter def get_twitter_token(): if 'twitter_oauth' in session:
def __init__(self, base_url='https://www.mediawiki.org/w', clean_url='https://www.mediawiki.org/wiki', default_return_to='frontend.index', consumer_key=None, consumer_secret=None): self._u = None if not consumer_key or not consumer_secret: raise Exception( 'MWOAuthBlueprintFactory needs consumer key and secret') self.base_url = base_url self.default_return_to = default_return_to self.oauth = OAuth() self.mwoauth = MWOAuthRemoteApp( self.oauth, 'mw.org', base_url=base_url + "/index.php", request_token_url=base_url + "/index.php", request_token_params={ 'title': 'Special:OAuth/initiate', 'oauth_callback': 'oob' }, access_token_url=base_url + "/index.php?title=Special:OAuth/token", authorize_url=clean_url + '/Special:OAuth/authorize', consumer_key=consumer_key, consumer_secret=consumer_secret, ) self.oauth.remote_apps['mw.org'] = self.mwoauth @self.mwoauth.tokengetter def get_mwo_token(token=None): return session.get('mwo_token') self.bp = Blueprint('mwoauth', __name__) @self.bp.route('/logout') def logout(): session['mwo_token'] = None session['username'] = None return redirect(gourl()) @self.bp.route('/login') def login(): self.default_return_to = gourl() redirector = self.mwoauth.authorize() if 'next' in request.args: oauth_token = session[self.mwoauth.name + '_oauthtok'][0] session[oauth_token + '_target'] = request.args['next'] redirector.headers[ 'Location'] += "&oauth_consumer_key=" + self.mwoauth.consumer_key return redirector @self.bp.route('/oauth-callback') @self.mwoauth.authorized_handler def oauth_authorized(resp): next_url_key = request.args['oauth_token'] + '_target' default_url = self.default_return_to next_url = session.pop(next_url_key, default_url) if resp is None: flash(msg['mwoauth-denied'], 'danger') return redirect(next_url) session['mwo_token'] = (resp['oauth_token'], resp['oauth_token_secret']) username = self.get_current_user(False) flash(msg['mwoauth-signin-successful'].format(username), 'success') return redirect(next_url)
# -*- coding: utf-8 -*- """Extensions module. Each extension is initialized in the app factory located in app.py.""" from flask_hashing import Hashing from flask_caching import Cache from flask_login import LoginManager from flask_oauth import OAuth from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy hashing = Hashing() login_manager = LoginManager() login_oauth = OAuth() db = SQLAlchemy() migrate = Migrate() cache = Cache()
from flask.ext.sqlalchemy import SQLAlchemy from flask_oauth import OAuth import os app = Flask(__name__) app.secret_key = os.environ.get('FLASK_APP_SECRET_KEY') app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get( 'DATABASE_URL', 'sqlite:///bikelist.db') db = SQLAlchemy(app) # Initializing OAuth FACEBOOK_APP_SECRET = os.environ.get('FACEBOOK_APP_SECRET', 'Not set') FACEBOOK_APP_ID = os.environ.get('FACEBOOK_APP_ID', 'Not set') 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, ')}) oauth2 = OAuth() bikeindex = oauth2.remote_app( 'bikeindex',