本文整理汇总了Python中api.models.User.auth_token方法的典型用法代码示例。如果您正苦于以下问题:Python User.auth_token方法的具体用法?Python User.auth_token怎么用?Python User.auth_token使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api.models.User
的用法示例。
在下文中一共展示了User.auth_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from api.models import User [as 别名]
# 或者: from api.models.User import auth_token [as 别名]
def get(self, provider_name):
if 'state' in session:
current_app.logger.debug(
'Session state: {0}'.format(str(session['state'])))
current_app.logger.debug('Session args state: {0}'.format(
str(request.args.get('state'))))
if str(session['state']) == str(request.args.get('state')):
code = request.args.get('code')
redirect_uri = \
'https://grove-api.herokuapp.com/login/facebook/callback'
params = {
'client_id':
social_config[provider_name]['consumer_key'],
'redirect_uri':
redirect_uri,
'client_secret':
social_config[provider_name]['consumer_secret'],
'code':
code
}
resp = requests.get('https://graph.facebook.com/' +
'v2.4/oauth/access_token', params=params)
try:
data = json.loads(resp.text)
current_app.logger.error('Data: ' + str(data))
except ValueError:
# Deeplink to iOS app
return redirect('grove://login_error?' +
'message=unable+to+load+json+i' +
'from+access+token+validation')
access_token = data['access_token']
user_id = self.validate_token(access_token)
if user_id is not None:
existing_user = User.query.filter_by(facebook_id=user_id).first()
if existing_user is None:
user_data = self.get_user_data(user_id, access_token)
if not user_data:
return redirect('grove://login_error?' +
'message=unable+to+parse+user+data')
new_user = User(facebook_id=user_id,
first_name=user_data['first_name'],
last_name=user_data['last_name'],
email=user_data['email'],
photo=user_data['profile_photo_url'],
facebook_token=access_token)
auth_token = new_user.generate_auth_token()
new_user.auth_token = auth_token.decode('ascii')
db.session.add(new_user)
db.session.commit()
# Deeplink to iOS App
return redirect('grove://signup/' +
'{id}/{auth_token}?first_name={'
'first_name}&last_name={'
'last_name}'.format(
id=new_user.uuid,
auth_token=new_user.auth_token,
first_name=new_user.first_name,
last_name=new_user.last_name) +
'&photo={photo}'.format(
photo=new_user.photo))
else:
# Deeplink to iOS App
return redirect('grove://login/' +
'{id}/{auth_token}?first_name={'
'first_name}&last_name={'
'last_name}'.format(
id=existing_user.uuid,
auth_token=existing_user.auth_token,
first_name=existing_user.first_name,
last_name=existing_user.last_name) +
'&photo={photo}'.format(
photo=existing_user.photo))
else:
current_app.logger.error(
'Session state does not match what is' +
'in session request.')
abort(401)
else:
current_app.logger.error('State not in session.')
abort(401)