def __init__(self, downloading_match_file_keywords=None, update_mister_tuple=None): super(Updater, self).__init__() self.downloading_match_file_keywords = downloading_match_file_keywords self.update_mister_tuple = update_mister_tuple self.oauth = OAuth() self.oauth.load() print2ln('Prepare download files...')
def twitter_logged_in(blueprint, token): if not token: flash("Failed to log in.", category="error") return redirect(url_for('main.index')) resp = blueprint.session.get("account/verify_credentials.json?include_email=true") if not resp.ok: msg = "Failed to fetch user info." flash(msg, category="error") return redirect(url_for('main.index')) info = resp.json() user_id = info.get("id", None) query = OAuth.query.filter_by( provider=blueprint.name, provider_user_id=str(user_id)) try: oauth = query.one() except NoResultFound: oauth = OAuth( provider=blueprint.name, provider_user_id=user_id, token=token) if oauth.user: user = oauth.user else: # Create a new local user account for this user username = info.get("name", "No name") email = info.get( "email", "Check request email address from users in your twitter app" ) user = User( username=username.lower(), email=email, created=dt.now(), token=token_urlsafe(), token_expiration=dt.now() ) password_generated = get_random_password_string(10) user.set_password(password_generated) # Associate the new local user account with the OAuth token oauth.user = user db.session.add_all([user, oauth]) db.session.commit() flash(_l("Successfully twitter connection"), 'success') login_user(user) return redirect(url_for('main.index'))
from flask import Flask, redirect, url_for, session, request, jsonify #from flask_oauthlib.client import OAuth #import os app = Flask(__name__) app.config[ 'GOOGLE_ID'] = "cloud.google.com/596422529465-652tfp1aerkj92s5hjdhsui5t4h54k86.apps.googleusercontent.com" app.config['GOOGLE_SECRET'] = "cloud.google.com/TegOpmHdBrf3PgHXsBNxEMZH" 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.route('/') def index(): if 'google_token' in session: me = google.get('userinfo') return jsonify({"data": me.data})