本文整理汇总了Python中gratipay.security.user.User.from_api_key方法的典型用法代码示例。如果您正苦于以下问题:Python User.from_api_key方法的具体用法?Python User.from_api_key怎么用?Python User.from_api_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gratipay.security.user.User
的用法示例。
在下文中一共展示了User.from_api_key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_auth_from_request
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_api_key [as 别名]
def get_auth_from_request(request):
"""Authenticate from a cookie or an API key in basic auth.
"""
user = None
if request.line.uri.startswith('/assets/'):
pass
elif 'Authorization' in request.headers:
header = request.headers['authorization']
if header.startswith('Basic '):
creds = header[len('Basic '):].decode('base64')
token, ignored = creds.split(':')
user = User.from_api_key(token)
# We don't require CSRF if they basically authenticated.
csrf_token = csrf._get_new_csrf_key()
request.headers.cookie['csrf_token'] = csrf_token
request.headers['X-CSRF-TOKEN'] = csrf_token
if 'Referer' not in request.headers:
request.headers['Referer'] = \
'https://%s/' % csrf._get_host(request)
elif SESSION in request.headers.cookie:
token = request.headers.cookie[SESSION].value
user = User.from_session_token(token)
request.context['user'] = user or User()
示例2: test_user_from_None_api_key_is_anonymous
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_api_key [as 别名]
def test_user_from_None_api_key_is_anonymous(self):
self.make_participant('alice')
self.make_participant('bob')
user = User.from_api_key(None)
assert user.ANON
示例3: test_user_can_be_loaded_from_api_key
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_api_key [as 别名]
def test_user_can_be_loaded_from_api_key(self):
alice = self.make_participant('alice')
api_key = alice.recreate_api_key()
actual = User.from_api_key(api_key).participant.username
assert actual == 'alice'
示例4: test_user_from_bad_api_key_is_anonymous
# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_api_key [as 别名]
def test_user_from_bad_api_key_is_anonymous(self):
user = User.from_api_key('deadbeef')
assert user.ANON