本文整理汇总了Python中oauth.OAuthSignIn.get_provider方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthSignIn.get_provider方法的具体用法?Python OAuthSignIn.get_provider怎么用?Python OAuthSignIn.get_provider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth.OAuthSignIn
的用法示例。
在下文中一共展示了OAuthSignIn.get_provider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例2: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例3: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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})
示例4: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例5: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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"))
示例6: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例7: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例8: oauth_authorize
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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()
示例9: oauth_authorize
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例10: oauth_authorize
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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()
示例11: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例12: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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('/')
示例13: oauth_authorize
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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()
示例14: oauth_callback
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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'))
示例15: decorated_function
# 需要导入模块: from oauth import OAuthSignIn [as 别名]
# 或者: from oauth.OAuthSignIn import get_provider [as 别名]
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)