本文整理汇总了Python中aleph.model.Role.by_api_key方法的典型用法代码示例。如果您正苦于以下问题:Python Role.by_api_key方法的具体用法?Python Role.by_api_key怎么用?Python Role.by_api_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aleph.model.Role
的用法示例。
在下文中一共展示了Role.by_api_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_credential_authz
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_api_key [as 别名]
def _get_credential_authz(credential):
if credential is None or not len(credential):
return
if ' ' in credential:
mechanism, credential = credential.split(' ', 1)
authz = Authz.from_token(credential, scope=request.path)
if authz is not None:
return authz
role = Role.by_api_key(credential)
if role is not None:
return Authz.from_role(role=role)
示例2: load_role
# 需要导入模块: from aleph.model import Role [as 别名]
# 或者: from aleph.model.Role import by_api_key [as 别名]
def load_role():
request.auth_roles = set([Role.system(Role.SYSTEM_GUEST)])
request.auth_role = None
request.logged_in = False
if session.get('user'):
request.auth_roles.update(session.get('roles', []))
request.auth_role = Role.by_id(session.get('user'))
request.logged_in = True
else:
api_key = request.args.get('api_key')
if api_key is None:
auth_header = request.headers.get('Authorization') or ''
if auth_header.lower().startswith('apikey'):
api_key = auth_header.split(' ', 1).pop()
role = Role.by_api_key(api_key)
if role is None:
return
request.auth_role = role
request.auth_roles.update([Role.system(Role.SYSTEM_USER), role.id])
request.logged_in = True