本文整理汇总了Python中website.oauth.models.ExternalAccount.load方法的典型用法代码示例。如果您正苦于以下问题:Python ExternalAccount.load方法的具体用法?Python ExternalAccount.load怎么用?Python ExternalAccount.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.oauth.models.ExternalAccount
的用法示例。
在下文中一共展示了ExternalAccount.load方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_user_auth
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def add_user_auth(self, node_addon, user, external_account_id):
external_account = ExternalAccount.load(external_account_id)
if external_account not in user.external_accounts:
raise HTTPError(http.FORBIDDEN)
try:
node_addon.set_auth(external_account, user)
except PermissionsError:
raise HTTPError(http.FORBIDDEN)
node = node_addon.owner
node.add_log(
action='dataverse_node_authorized',
params={
'project': node.parent_id,
'node': node._id,
},
auth=Auth(user=user),
)
result = self.serializer(
node_settings=node_addon,
user_settings=user.get_addon('dataverse'),
).serialized_node_settings
return {'result': result}
示例2: get_account_or_error
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def get_account_or_error(self, addon_name, external_account_id, auth):
external_account = ExternalAccount.load(external_account_id)
if not external_account:
raise exceptions.NotFound('Unable to find requested account.')
if external_account not in auth.user.external_accounts:
raise exceptions.PermissionDenied('Requested action requires account ownership.')
if external_account.provider != addon_name:
raise Conflict('Cannot authorize the {} addon with an account for {}'.format(addon_name, external_account.provider))
return external_account
示例3: add_user_auth
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def add_user_auth(self, node_addon, user, external_account_id):
external_account = ExternalAccount.load(external_account_id)
if external_account not in user.external_accounts:
raise HTTPError(http.FORBIDDEN)
try:
node_addon.set_auth(external_account, user)
except PermissionsError:
raise HTTPError(http.FORBIDDEN)
result = self.serialize_settings(node_addon, user)
return {'result': result}
示例4: add_user_auth
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def add_user_auth(self, node_addon, user, external_account_id):
external_account = ExternalAccount.load(external_account_id)
if external_account not in user.external_accounts:
raise HTTPError(http.FORBIDDEN)
try:
node_addon.set_auth(external_account, user)
except PermissionsError:
raise HTTPError(http.FORBIDDEN)
result = self.serializer(
node_settings=node_addon,
user_settings=user.get_addon(self.provider_name),
).serialized_node_settings
result['validCredentials'] = self.check_credentials(node_addon)
return {'result': result}
示例5: oauth_disconnect
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def oauth_disconnect(external_account_id, auth):
account = ExternalAccount.load(external_account_id)
user = auth.user
if account is None:
HTTPError(http.NOT_FOUND)
if account not in user.external_accounts:
HTTPError(http.FORBIDDEN)
# iterate AddonUserSettings for addons
for user_settings in user.get_oauth_addons():
user_settings.revoke_oauth_access(account)
user_settings.save()
# ExternalAccount.remove_one(account)
# # only after all addons have been dealt with can we remove it from the user
user.external_accounts.remove(account)
user.save()
示例6: googledrive_import_user_auth
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def googledrive_import_user_auth(auth, node_addon, **kwargs):
""" Import googledrive credentials from the currently logged-in user to a node.
"""
user = auth.user
external_account_id = request.get_json().get('external_account_id')
external_account = ExternalAccount.load(external_account_id)
if external_account not in user.external_accounts:
raise HTTPError(http.FORBIDDEN)
try:
node_addon.set_auth(external_account, user)
except PermissionsError:
raise HTTPError(http.FORBIDDEN)
result = GoogleDriveSerializer(
node_settings=node_addon,
user_settings=user.get_addon('googledrive'),
).serialize_settings(node_addon, user)
return result
示例7: creds_are_valid
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def creds_are_valid(ea_id):
logger.warn('Validating credentials for externalaccount {}'.format(ea_id))
ea = ExternalAccount.load(ea_id)
if ea.provider == 'github':
try:
GitHubClient(external_account=ea).user()
except (GitHubError, IndexError):
logger.info('Invalid creds: {}'.format(ea_id))
return False
elif ea.provider == 'dropbox':
try:
DropboxClient(ea.oauth_key).account_info()
except (ValueError, IndexError, ErrorResponse):
logger.info('Invalid creds: {}'.format(ea_id))
return False
else:
raise Exception('Unexpected provider: {}'.format(ea.provider))
logger.info('Valid creds: {}'.format(ea_id))
return True
示例8: _import_auth
# 需要导入模块: from website.oauth.models import ExternalAccount [as 别名]
# 或者: from website.oauth.models.ExternalAccount import load [as 别名]
def _import_auth(auth, node_addon, user_addon, **kwargs):
"""Import add-on credentials from the currently logged-in user to a node.
"""
external_account = ExternalAccount.load(
request.json['external_account_id']
)
if external_account not in user_addon.external_accounts:
raise HTTPError(http.FORBIDDEN)
try:
node_addon.set_auth(external_account, user_addon.owner)
except PermissionsError:
raise HTTPError(http.FORBIDDEN)
node_addon.save()
return {
'result': Serializer().serialize_settings(node_addon, auth.user),
'message': 'Successfully imported access token from profile.',
}