def oauth_callback(): if 'jwt' in request.cookies: token = verify_token(request.cookies['jwt']) if token is not None: return redirect('/inventory') oauth = OAuthSignIn() id_, email, admin, name, phone = oauth.callback() print(phone) if id_ is None: flash('Authentication failed.') return redirect('/inventory') if User.query.filter_by(email=email).count() == 0: admin = admin or email in config.ADMINS user = User( email=email, is_admin=admin, name=name, phone=phone, ) db.session.add(user) db.session.commit() # generate token since we cut out quill token = generate_auth_token(email) response = app.make_response(redirect('/inventory')) response.set_cookie('jwt', token.encode('utf-8')) return response
def oauth_callback(): try: auth = OAuthSignIn(app) return auth.callback() except Exception as e: print e auth = OAuthSignIn(app) session['username'] = auth.generateRandomUsername() session['isAnonymous'] = True return redirect(url_for('home'))
def preauth(): try: print request.method if(request.method == 'POST'): scope_list = list(request.form) auth_scope = 'user_read' if(len(scope_list) > 0): for i in range(0, len(scope_list)): auth_scope += '+' + scope_list[i] auth = OAuthSignIn(app) return auth.authorize(auth_scope) return render_template('preauth.jade', title = 'Pre Auth', UrlFor = url_for('preauth')) except Exception as e: print e
def oauth_callback(provider): if not current_user.is_anonymous: print("hello world") return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) return redirect(url_for('index'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) if provider == 'google': username, email = oauth.callback() if email is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(email=email).first() if not user: user = User(nickname=username, email=email, provider=provider) db.session.add(user) db.session.commit() else: #facebook authentication social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username, email=email, provider=provider) db.session.add(user) db.session.commit() login.login_user(user, True) return redirect(url_for('index'))
def oauth_authorize(provider): if g.user: #return render_template('msg.html', message="Not logged in (not g.user).") return redirect(url_for('homepage')) oauth = OAuthSignIn.get_provider(provider) #return render_template('msg.html', message="Logged in yes. g.user.") return oauth.authorize()
def oauth_callback(provider): # rand_pass will be a new password every time a user logs in # with oauth. temp_pass = str(uuid.uuid4()) # lets create the oauth object that will issue the request. oauth = OAuthSignIn.get_provider(provider) # assign the response email, first_name, last_name = oauth.callback() if email is None: return unauthorized('Invalid credentials') # see if this user already exists, and # and give the user a brand new password. user = User.query.filter_by(email=email).first() if user: user.password = temp_pass # if there is no user, create a new one and setup # it's defaults and give it a new password. else: user = User.insert_user(password=temp_pass, username=email, email=email, first_name=first_name, last_name=last_name) return jsonify({'uuid': temp_pass, 'username': email})
def oauth_callback(provider): try: if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) mlh_id, name, email = oauth.callback() if mlh_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(mlh_id=mlh_id).first() if not user: # Create, add and login new user. Redirect to /register user = User(mlh_id=mlh_id, name=name, email=email) db.session.add(user) db.session.commit() login_user(user, True) app.logger.info("{}[{}] at {} logged in for the first time".format( current_user.name, current_user.id, request.remote_addr)) return redirect(url_for('register')) else: # Login new user. Redirect to / login_user(user, True) app.logger.info("{}[{}] at {} logged in".format( current_user.name, current_user.id, request.remote_addr)) return redirect(url_for('index')) except Exception as e: return render_template('500.html', error=str(e))
def oauth_authorize(provider): if provider == "instagram": logging.debug("An unavailable social media account has been provided.") return render_template('error.html') # Google needs to be handled separately if provider == 'google': # Create an OAuth flow to the google servers using the info in the config logging.debug("Beginning dance for google OAuth") flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file( app.config['CLIENT_SECRETS_FILE'], scopes=app.config['SCOPES']) logging.debug("Google OAuth flow connection established") # Get the URI to redirect the user back to the website once auth'd on google services flow.redirect_uri = url_for('oauth2callback', _external=True) # Get link to direct user to google authorization_url, state = flow.authorization_url( access_type='offline', include_granted_scopes='true') # Store the state so the callback can verify the auth server response. session['state'] = state # Return the google auth url to user return redirect(authorization_url) else: logging.debug( "Facebook or Twitter requested, beginning relevant OAuth dance") oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def oauth_callback(provider): """ Handles redirect back from OAuth provider Obtains the specified provider callback method and calls it for authentication. If successful checks the db and register new user when necessary. Then logins via flask-login and redirects to the dashboard. Parameters ---------- provider : str Provider name corresponding to the OAuthSignIn.provider_name """ if not current_user.is_anonymous: return redirect(url_for('games.list')) oauth = OAuthSignIn.get_provider(provider) social_id, username = oauth.callback() if social_id is None: flash('Authentication failed') return redirect(url_for('home.homepage')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, username=username) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('games.list'))
def oauth_callback(provider): if not g.user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) if email is None: flash('Authentication failed. User account requires valid email.\ Please sign up, or log in with a different account') return redirect(url_for('index')) user = User.query.filter_by(email=email).first() if not user: if username is None or username == "": username = email.split('@')[0] username = User.create_unique_username(username) user = User(username=username, email=email) db.session.add(user) db.session.commit() # make the user follow him/herself db.session.add(user.follow(user)) db.session.commit() login_user(user, True) return redirect(url_for('profile'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('main.index')) oauth = OAuthSignIn.get_provider(provider) try: social_id, username, email,picture,friends= oauth.callback() print('/friends:',friends[0]) except: print("except") # for element in friends: # print('element:',element[0]) # ff=int(element[0] or 0) # if friend : # print("No friend here") # else: # print(element[0]) if social_id is None: flash('Authentication failed.') return redirect(url_for('main.index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id,username=username, email=email) db.session.add(user) db.session.commit() login_user(user, True) # return redirect(url_for('main.index',friends=friends['data'])) return redirect(url_for('main.index',friends=["www","sss"]))
def oauth_authorize(provider): print 'Entro nella function oauth_authorize' if not current_user.is_anonymous(): return redirect(url_for('index')) print 'sono anonimo' oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def oauth_authorize(provider): print "hellooo ", provider if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) print "oath=", oauth return "Done!"
def oauth_callback(provider): next_page = session.get('next_page', 'index') if not current_user.is_anonymous: return redirect(url_for(next_page)) oauth = OAuthSignIn.get_provider(provider) token = oauth.callback() session['token'] = token client = Fitbit(app.config['OAUTH_CREDENTIALS'][provider]['id'], app.config['OAUTH_CREDENTIALS'][provider]['secret'], access_token=token['access_token'], refresh_token=token['refresh_token']) fitbit_client = None if provider == 'fitbit': fitbit_client = client if fitbit_client is not None: me = fitbit_client.get_user_profile() social_id = 'fitbit_' + me['user']['encodedId'] full_name = me['user']['fullName'] nickname = me['user'].get('nickname') if social_id is None: flash('Authentication failed.') return redirect(url_for(next_page)) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, full_name=full_name, nickname=nickname) db.session.add(user) db.session.commit() login_user(user, remember=True) return redirect(url_for(next_page))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, firstname, lastname, refresh_token, access_token, token_expires = oauth.callback( ) if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username, fullname=str(firstname + " " + lastname), refresh_token=refresh_token, access_token=access_token, token_expires=token_expires, progress_counter=0) db.session.add(user) db.session.commit() else: user.refresh_token = refresh_token user.access_token = access_token user.token_expires = token_expires db.session.commit() login_user(user, True) return redirect(url_for('index'))
def oauth_authorize(provider): if not current_user.is_anonymous: return redirect(url_for('home')) oauth = OAuthSignIn.get_provider(provider) session['state'] = oauth.state session['next'] = request.args.get('next', '') return oauth.authorize()
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email, organization_id = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter(User.social_id == social_id).first() if not user: user = User( social_id=social_id, nickname=username, email=email, organization_id=organization_id, roles=[ ('EDITOR', 'ADMINISTRADOR')[current_app.config.get('DEV_MODE') is True] ]) db.session.add(user) db.session.flush() if login_user(user): session.permanent = True return redirect(url_for('index'))
def oauth_callback(provider): if not current_user.is_anonymous(): return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email,fullname,gender,timezone,image,locale,app_using_friends = oauth.callback() #print image if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username,username=fullname,email=email,gender=gender,timezone=timezone,image=image,country=locale) db.session.add(user) db.session.commit() # add friends in graph node for friend in app_using_friends: friend_social_id = "facebook$"+friend['id'] friend_obj = User.query.filter_by(social_id=friend_social_id).first() if friend_obj: friend_id = friend_obj.id is_friend = Graph_friends.query.filter_by(source_user_id=user.id,end_user_id=friend_id).first() if not is_friend: #add into the graph add_node = Graph_friends(source_user_id=user.id,end_user_id=friend_id) db.session.add(add_node) db.session.commit() login_user(user, True) return redirect(url_for('index'))
def oauth_callback(provider): oauth = OAuthSignIn.get_provider(provider) social_id, access_token, access_token_secret, fb_page_id = oauth.callback() if social_id is None: logging.debug("Authentication failed") flash('Authentication failed.') return redirect(url_for('index')) if provider == 'twitter': logging.debug( "Writing twitter credentials to account for user with coid={} and uid={}" .format(current_user.coid, current_user.uid)) current_user.twitter_access_token = access_token current_user.twitter_access_token_secret = access_token_secret db.session.commit() elif provider == 'facebook': logging.debug( "user with coid={} and uid={} first page access token is being written to the database" .format(current_user.coid, current_user.uid)) current_user.facebook_access_token_secret = access_token_secret current_user.facebook_access_token = fb_page_id db.session.commit() return redirect(url_for('index'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) if provider == 'google': username, email = oauth.callback() if email is None: flash('Authentication failed.') return redirect(url_for('index')) user=User.query.filter_by(email=email).first() if not user: user = User(nickname=username, email=email, provider=provider) db.session.add(user) db.session.commit() else: #facebook authentication social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username, email=email, provider=provider) db.session.add(user) db.session.commit() login.login_user(user, True) return redirect(url_for('index'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) username, email, picture, source = oauth.callback() if email is None: # I need a valid email address for my user identification flash('Authentication failed.') return redirect(url_for('index')) # Look if the user already exists user = session.query(User).filter_by(email=email).first() if not user: # Create the user. Try and use their name returned by Google, # but if it is not set, split the email address at the @. nickname = username if nickname is None or nickname == "": nickname = email.split('@')[0] print "nickname: ", nickname # We can do more work here to ensure a unique nickname, if you # require that. user = User(username=nickname, email=email, picture=picture, user_source=source) session.add(user) session.commit() # Log in the user, by default remembering them for their next visit # unless they log out. user.last_login_date = datetime.utcnow() session.add(user) session.commit() login_user(user, remember=False) return redirect(url_for('index'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('login_page')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('login_page')) # print social_id, username, email # table = "login" fb_details = { 'username': username, 'auth_token': social_id, 'login_source': provider, 'email_id': email } # result = obj.insert(table, data) entry = db.select('login', {'username': fb_details['username']}) if entry: print 'Record Exists: ' + str(entry) # return dash(entry) return redirect(url_for('dash', messages=entry)) else: # SELECT username from login where username = '******'; query = "INSERT INTO `shield`.`login` (`username`, `email_id`, `auth_token`, `login_source`) " \ "VALUES ('"+ fb_details['username'] +"', '" + fb_details['email_id'] + "', '" + fb_details['auth_token'] + "', '" + fb_details['login_source'] + "');" db.execute_query(query) result = db.select('login', {'username': fb_details['username']}) return redirect(url_for('dash', messages=result))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email, dob, friend, g = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username, email=email, dob=dob, gender=g) db.session.add(user) db.session.commit() for x in range(len(friend)): res = db.session.query(Userfriends).filter_by(f1_id=social_id, f2_id=friend[x]).all() if not res: f = Userfriends(f1_id=social_id, f2_id=friend[x]) db.session.add(f) db.session.commit() login_user(user, True) return redirect(url_for('index'))
def oauth_callback(provider): """ Callback function for OAuth flow. The OAuth provider redirects back to the application after the user authenticates and gives permission to share information. """ if not current_user.is_anonymous: return redirect(url_for('showGames')) # Instantiate the OAuthSignIn provider oauth = OAuthSignIn.get_provider(provider) # Get the social_id, nickname and email from the provider social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('showGames')) # Query for a user with the social_id previously obtained user = session.query(User).filter_by(social_id=social_id).first() # If the previous query does not returns an user, create it and add it to # the database if not user: user = User(social_id=social_id, nickname=username, email=email) session.add(user) session.commit() login_user(user, True) return redirect(url_for('showGames'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for("index")) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() print ("llamada despues de callback") print ("social_id " + social_id) print ("username " + username) print ("email " + email) if social_id is None: flash("Authentication failed.") return redirect(url_for("index")) user = User.query.filter_by(social_id=social_id).first() if not user: print ("no existia el usuario, lo persisto") user = User(social_id=social_id, nickname=username, email=email) db.session.add(user) db.session.commit() print ("usuario no logueado") print (current_user.is_anonymous) print (current_user.is_authenticated) login_user(user, True) print ("usuario logueado") print ("current user" + str(current_user)) print str(user) return redirect(url_for("index"))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) access_token, github_user = oauth.callback() if access_token is None: flash('Authentication failed.') return redirect(url_for('login')) if provider == 'github': username = github_user['login'] elif provider == 'gitlab': username = github_user['username'] user = User.query.filter_by(username=username).first() if not user: username = User.make_unique_nickname(username) user = User(username=username, realname=github_user['name'], email=github_user['email']) db.session.add(user) db.session.commit() login_user(user, remember=True) flask_session['active_token'] = access_token return redirect(url_for('index'))
def oauth_authorize(provider): if not current_user.is_anonymous: return redirect(url_for('index')) #return redirect(url_for('mainpage')) session['logstatus']=0 oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def oauth_authorize(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def oauth_authorize(provider): if not current_user.is_anonymous: return redirect(url_for('index')) try: oauth = OAuthSignIn.get_provider(provider) return oauth.authorize() except: return redirect(url_for_security('login'))
def oauth_authorize(provider): if not current_user.is_anonymous: return redirect(url_for('control_panel')) if provider == 'twitter': oauth = OAuthSignIn.get_provider(provider) return oauth.authorize() else: return redirect(url_for('google_callback'))
def oauth_callback(provider): oauth = OAuthSignIn.get_provider(provider) oauth_session = oauth.callback() res = oauth_session.get('username').json() session['authenticated'] = True session['username'] = res['username'] session['tgt'] = res['token'] return redirect(url_for('authenticated'))
def oauth_authorize(provider): try: if not current_user.is_anonymous(): return redirect(url_for('build_index')) oauth = OAuthSignIn.get_provider(provider) except Exception, e: logger.error('some error happened: {0}'.format(e)) return redirect(url_for('build_index'))
def oauth_authorize(provider, state): # Flask-Login function if not current_user.is_anonymous: return redirect(url_for('index')) if state != app.config['SECRET_KEY']: flash("Incorrect state parameter") return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def oauth_authorize(provider): try: if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) return oauth.authorize() except Exception as e: return render_template('500.html', error=str(e))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) username, email = oauth.callback() user = User(nickname=username, email=email, code=request.args.get('code')) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for('index'))
def recommend(): try: #if user is not logged in or does not have a random username assigned, then we should give them one if((not 'username' in session) or session['username'] == '' or (not 'isAnonymous' in session)): auth = OAuthSignIn(app) session['username'] = auth.generateRandomUsername() session['isAnonymous'] = True _recommendations = twitchrecommender.generateRecommendationListForUser(session['username'], session['isAnonymous']) twitchrecommender.storeFollowerRecommendations(session['username'],_recommendations) session['rec_time_out'] = time.time() + 900 session['dir'] = 'up' return redirect(url_for('recommendations', rank=1)) except Exception as e: print e, 'B', sys.exc_traceback.tb_lineno
def oauth_callback(provider): oauth = OAuthSignIn.get_provider(provider) try: social_id, name, username, email, profile_picture, access_token, access_token_exp, access_token_secret, refresh_token = oauth.callback( ) except ValueError as v: print "Callback failed to return all user values" print str(v) return redirect(url_for('home')) except Exception as e: print "Callback failed for some reason" print str(e) return redirect(url_for('home')) if social_id is None: return redirect(url_for('home')) # Query database for existing users with social_id user = User.query.filter_by(social_id=social_id).first() if not user: print " * User does not exist in database" # If provider is google but no refresh token is provided then that means they had # already authorized our application but we're in this logic branch because they # do not exist in our users table. # This can help if our database goes down and users try to log in, we cannot let # Google users continue because we cannot refresh their access tokens if provider == 'google' and refresh_token is None: return redirect(url_for('home')) # Try and use their name, but if not set, use first part of email if name is None or name == "": name = username user = User(social_id=social_id, name=name, username=username, email=email, profile_picture=profile_picture, provider=provider, last_active=int(time.time()), access_token=access_token, access_token_exp=access_token_exp, access_token_secret=access_token_secret, refresh_token=refresh_token) db.session.add(user) db.session.commit() print " * Updating user values (AT, ATE, ATS, RT)" # Update the current access_token and access_token_exp # in the db with values just returned by oauth.callback() user.access_token = access_token user.access_token_exp = access_token_exp user.access_token_secret = access_token_secret # This is for if a google user revokes access and tries to log in re-granting access # our current refresh token on file has been revoked so we need to update, if given user.refresh_token = refresh_token or user.refresh_token db.session.commit() login_user(user, remember=True) return redirect(url_for('home'))
def oauth_callback(provider): # oauth calls us once we've been granted a token # from oauth provider if not current_user.is_anonymous: # not logged in return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) me = oauth.callback() ''' oauth.callback() returns: { 'FirstName' : 'John', 'LastName' : 'Bigbooty', 'Email' : '*****@*****.**', 'DisplayName' : 'Bigbooty, John', 'Organization' : 'Yoyodyne', 'MembershipLevel' : { 'Id' : 5059174, 'Url' : 'https://api.wildapricot.org/v2/accounts/123456/MembershipLevels/1059174', 'Name' : 'Key (Legacy)' }, 'Status' : 'Active', 'Id' : 90534910, 'Url' : 'https://api.wildapricot.org/v2/accounts/123456/Contacts/50534910', 'IsAccountAdministrator' : True, 'TermsOfUseAccepted' : True } ''' if not('Email' in me): flash("ERROR oauth_callback(): " + me['Message'],'error') return redirect(url_for('index')) # is this user in the DB ? user = User.query.filter_by(email=me['Email']).first() if not user: # if not, add them user = User( first_name = me['FirstName'], last_name = me['LastName'], email = me['Email'], id = me['Id'] ) db.session.add(user) db.session.commit() # officially login them into flask_login system login_user(user, True) return redirect(url_for('index'))
def oauth_authorize(provider): print "Authorize" if not current_user.is_anonymous: "not anonim" return redirect(url_for('index')) print "anonim" print provider oauth = OAuthSignIn.get_provider(provider) print oauth print "get oauth" return oauth.authorize()
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email, user_likes, posts = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) else: if not user_exists(username): user_posts = [] for post in posts['data']: try: user_posts.append(facebook_post(post)) except: pass post_string = build_post_string(user_posts) send_data = {'content': post_string} response = requests.post( "http://c9b4dbd0.ngrok.io/getUserTopic", data=json.dumps(send_data), headers={'content-type': 'application/json'}) response_dict = json.loads(response.text) user_topics = [] user_topics.append(response_dict["topicNo1"]) user_topics.append(response_dict["topicNo2"]) user_topics.append(response_dict["topicNo3"]) user_topics.append(response_dict["topicNo4"]) user_topics.append(response_dict["topicNo5"]) print(user_topics) try: es.index(index='user', doc_type='existing_users', body={ 'username': username, 'favorite_topics': json.dumps(user_topics), }) except: print('User already exists') user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username, email=email) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for('index'))
def oauth_authorize(provider): ''' The route ensures that the user is not logged in, and then obtains the OAuthSignIn subclass appropiate for the given provider, and invokes its authorize() method to initiate the process ''' if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def oauth_callback(provider): oauth = OAuthSignIn.get_provider(provider) social, username, email = oauth.callback() if social is None: flash('Authentication failed.') return redirect(url_for('login')) user = query_social_user(social); session['social'] = social if user is None: insert_social_user(social) return redirect('/')
def oauth_callback(provider): oauth = OAuthSignIn.get_provider(provider) try: social_id, name, username, email, profile_picture, access_token, access_token_exp, access_token_secret, refresh_token = oauth.callback() except ValueError as v: print "Callback failed to return all user values" print str(v) return redirect(url_for('home')) except Exception as e: print "Callback failed for some reason" print str(e) return redirect(url_for('home')) if social_id is None: return redirect(url_for('home')) # Query database for existing users with social_id user = User.query.filter_by(social_id=social_id).first() if not user: print " * User does not exist in database" # If provider is google but no refresh token is provided then that means they had # already authorized our application but we're in this logic branch because they # do not exist in our users table. # This can help if our database goes down and users try to log in, we cannot let # Google users continue because we cannot refresh their access tokens if provider == 'google' and refresh_token is None: return redirect(url_for('home')) # Try and use their name, but if not set, use first part of email if name is None or name == "": name = username user = User(social_id=social_id, name=name, username=username, email=email, profile_picture=profile_picture, provider=provider, last_active=int(time.time()), access_token=access_token, access_token_exp=access_token_exp, access_token_secret=access_token_secret, refresh_token=refresh_token) db.session.add(user) db.session.commit() print " * Updating user values (AT, ATE, ATS, RT)" # Update the current access_token and access_token_exp # in the db with values just returned by oauth.callback() user.access_token = access_token user.access_token_exp = access_token_exp user.access_token_secret = access_token_secret # This is for if a google user revokes access and tries to log in re-granting access # our current refresh token on file has been revoked so we need to update, if given user.refresh_token = refresh_token or user.refresh_token db.session.commit() login_user(user, remember=True) return redirect(url_for('home'))
def decorated_function(*args, **kwargs): oauth = OAuthSignIn.get_provider(current_user.provider) if oauth.oauth_session is None: print " * Session is None, redirecting to authorize" return redirect(url_for('oauth_authorize', provider=current_user.provider)) if current_user.provider.lower() == "google": print " * Provider is google" if current_user.access_token_exp <= time.time(): print " * Refreshing Google session with refresh token" refreshAccessToken(current_user.refresh_token) print " * Valid Session - Moving on with request" return f(*args, **kwargs)
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('poll_machine.index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: return redirect(url_for('poll_machine.index')) user = dal.find_user(social_id) if not user: user = dal.create_user(social_id, username, email) login_user(user, True) return redirect(url_for('poll_machine.index'))
def oauth_authorize(provider): """ Creates the OAuthSignIn instance with the given provider, then continues the authorization flow. """ # Check if the user is not logged in already if not current_user.is_anonymous: return redirect(url_for('showGames')) # If not logged in, then we instantiate the corresponding OAuthSignIn # subclass oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def decorated_function(*args, **kwargs): oauth = OAuthSignIn.get_provider(current_user.provider) if oauth.oauth_session is None: print " * Session is None, redirecting to authorize" return redirect( url_for('oauth_authorize', provider=current_user.provider)) if current_user.provider.lower() == "google": print " * Provider is google" if current_user.access_token_exp <= time.time(): print " * Refreshing Google session with refresh token" refreshAccessToken(current_user.refresh_token) print " * Valid Session - Moving on with request" return f(*args, **kwargs)
def oauth_callback(provider): oauth = OAuthSignIn.get_provider(provider) social_id, username, email, picture = oauth.callback() user = session.query(User).filter_by(email=email).first() if not user: user = User(username = username, picture = picture, email = email) session.add(user) membership = OAuthMembership(provider = provider, provider_userid = social_id, user = user) session.add(membership) session.commit() login_session['username'] = user.username token = user.generate_auth_token(1600) return redirect(url_for('index', token = token))
def oauth_callback(): if not current_user().is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider('fablabs') try: result = oauth.callback() except: result = {} data = result.get('data', None) if data is None: flash('Authentication failed.') return redirect(url_for('index')) login_user(data) return redirect(url_for('index'))
def home(): if( not 'isAnonymous' in session): if('oauth_access_token' in session and session['oauth_access_token'] != ''): session['isAnonymous'] = False else: auth = OAuthSignIn(app) #random username used for recommendation storage session['username'] = auth.generateRandomUsername() session['isAnonymous'] = True if ('oauth_access_token' in session and session['oauth_access_token'] != '') or ('isAnonymous' in session and session['isAnonymous'] == False): try: return render_template('index.jade',title = 'Home Page',year = datetime.now().year, username=session['username'], isAnonymous = session['isAnonymous']) except Exception as e: print e, 'A' else: try: return render_template('index.jade',title = 'Home Page',year = datetime.now().year, username='', isAnonymous = session['isAnonymous']) except Exception as e: print e, 'C' return redirect(url_for('error'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for("index")) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: flash("Authentication failed.") return redirect(url_for("index")) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username, email=email) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for("index"))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, email, name = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id,email=email,name=name) usrdb.session.add(user) usrdb.session.commit() addCurator({"uid":email,"name":name,"tags":[],"rating":5}) login_user(user, True) return redirect(url_for('index'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('personal')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email, data = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('news')) user = User.query.filter_by(id=social_id).first() if not user: user = User(id=social_id, username=username, email=email, general=0)#, friends=friends) #social_id=social_id, db.session.add(user) db.session.commit() entity_extract(social_id, data, 0) login_user(user, True) return redirect(url_for('personal'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.', 'error') return redirect(url_for('index')) user = models.User.query.filter_by(social_id=social_id).first() if not user: user = models.User(social_id=social_id, nickname=username, email=email) db.session.add(user) db.session.commit() login_user(user, True) flash('Successfully logged in.', 'success') return redirect(url_for('index'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect('/') oauth = OAuthSignIn.get_provider(provider) social_id, username, email, name = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect('/') user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=name, email=email, data=str([0] * 15)) db.session.add(user) db.session.commit() login_user(user, True) return redirect('/')
def oauth_callback(provider): oauth = OAuthSignIn.get_provider(provider) user_dict = oauth.callback() if (isinstance(user_dict, dict) and user_dict['oauth_token'] is None) or (isinstance(user_dict, tuple) and user_dict[0] is None): app.logger.warning("Authentication failed") flash('Authentication failed.') return redirect(url_for('index')) gr_response = user_dict['user_info']['GoodreadsResponse']['user'] user = User.query.filter_by(user_id=gr_response['@id']).first() if not user: user = User(user_id=gr_response['@id'], name=gr_response['name'], request_token=user_dict['request_token'], request_secret=user_dict['request_secret'], oauth_token=user_dict['oauth_token']) db.session.add(user) db.session.commit() session['user_id1'] = gr_response['@id'] return redirect(url_for('user_profile'))
def oauth_callback(provider): print 'Entro nella function oauth_callback' if not current_user.is_anonymous(): return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) facebookId, username = oauth.callback() if facebookId is None: flash('Authentication failed.') return redirect(url_for('index')) user = User.query.filter_by(facebookId=facebookId).first() session['facebookId'] = facebookId if not user: user = User(facebookId=facebookId, username=username) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for('index'))
def oauth_callback(provider): if g.user is not None and g.user.is_authenticated: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('login')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, username=username, email=email) db.session.add(user) db.session.commit() # make the user follow him/herself db.session.add(user.follow(user)) db.session.commit() login_user(user, True) return redirect(url_for('index'))