本文整理匯總了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