本文整理汇总了Python中openspending.model.account.Account.by_api_key方法的典型用法代码示例。如果您正苦于以下问题:Python Account.by_api_key方法的具体用法?Python Account.by_api_key怎么用?Python Account.by_api_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.account.Account
的用法示例。
在下文中一共展示了Account.by_api_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_user_from_request
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_api_key [as 别名]
def load_user_from_request(request):
api_key = request.args.get('api_key')
if api_key and len(api_key):
account = Account.by_api_key(api_key)
if account:
return account
api_key = request.headers.get('Authorization')
if api_key and len(api_key) and ' ' in api_key:
method, api_key = api_key.split(' ', 1)
if method.lower() == 'apikey':
account = Account.by_api_key(api_key)
if account:
return account
return None
示例2: authenticate
# 需要导入模块: from openspending.model.account import Account [as 别名]
# 或者: from openspending.model.account.Account import by_api_key [as 别名]
def authenticate(self, environ, identity):
"""
Try to authenticate user based on api key identity
"""
# If identity has apikey we get the account by the api key
# and return none if no account or apikey is found is found
if 'apikey' in identity:
acc = Account.by_api_key(identity.get('apikey'))
if acc is not None:
return acc.name
return None