本文整理匯總了Python中webapp2_extras.appengine.auth.models.User.get_by_auth_token方法的典型用法代碼示例。如果您正苦於以下問題:Python User.get_by_auth_token方法的具體用法?Python User.get_by_auth_token怎麽用?Python User.get_by_auth_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webapp2_extras.appengine.auth.models.User
的用法示例。
在下文中一共展示了User.get_by_auth_token方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: authenticate
# 需要導入模塊: from webapp2_extras.appengine.auth.models import User [as 別名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_token [as 別名]
def authenticate(request,id):
auth = Auth(request)
token = request.headers['Authorization']
user, ts = User.get_by_auth_token(id, token)
if not user:
return None
elif not user.validate_token(id, 'auth', token):
return None
return user
示例2: validate
# 需要導入模塊: from webapp2_extras.appengine.auth.models import User [as 別名]
# 或者: from webapp2_extras.appengine.auth.models.User import get_by_auth_token [as 別名]
def validate(*args, **kwargs):
""" Validates the User ID and token sent in an endpoints request."""
# Get the headers from the self arg
headers = args[0].request_state.headers
token = headers.get('Token')
if headers.get('User-Id') is None:
raise endpoints.UnauthorizedException(MESSAGE_UNAUTHORIZED)
user_id = int(headers.get('User-Id'))
user, timestamp = User.get_by_auth_token(user_id, token)
if user:
return endpoints_method(*args, **kwargs)
else:
logging.warn('Invalid API request! User ID:%s, token:%s'
%(user_id, token))
raise endpoints.UnauthorizedException(MESSAGE_UNAUTHORIZED)