def disconnect(external_account_id, institution_id, user): """disconnect OAuth""" account = ExternalAccount.load(external_account_id) if not account: raise Http404 rdm_addon_option = get_rdm_addon_option(institution_id, account.provider) if not rdm_addon_option.external_accounts.filter(id=account.id).exists(): raise Http404 app = flask.Flask(__name__) with app.test_client() as c: # Create dummy Flask communication. # revoke_oauth_access method goes through flask # in order to confirm the user is logged in. c.get('/') # iterate AddonUserSettings for addons for user_settings in user.get_oauth_addons(): if user_settings.oauth_provider.short_name == account.provider: user_settings.revoke_oauth_access(account, Auth(user)) user_settings.save() # # only after all addons have been dealt with can we remove it from the user rdm_addon_option.external_accounts.remove(account) rdm_addon_option.save() user.external_accounts.remove(account) user.save() return HttpResponse('')
def get_object(self): user_settings = self.get_addon_settings(check_object_permissions=False) account_id = self.kwargs['account_id'] account = ExternalAccount.load(account_id) if not (account and user_settings.external_accounts.filter(id=account.id).exists()): raise NotFound('Requested addon unavailable') return account
def get_object(self): user_settings = self.get_addon_settings(check_object_permissions=False) account_id = self.kwargs['account_id'] account = ExternalAccount.load(account_id) if not (account and user_settings.external_accounts.filter(id=account.id).exists()): raise NotFound('Requested addon unavailable') return account
def oauth_disconnect(external_account_id, auth): account = ExternalAccount.load(external_account_id) user = auth.user if account is None: raise HTTPError(http.NOT_FOUND) if not user.external_accounts.filter(id=account.id).exists(): raise HTTPError(http.FORBIDDEN) # iterate AddonUserSettings for addons for user_settings in user.get_oauth_addons(): if user_settings.oauth_provider.short_name == account.provider: 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()
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 not user_addon.external_accounts.filter(id=external_account.id).exists(): 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.', }
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 not user_addon.external_accounts.filter( id=external_account.id).exists(): raise HTTPError(http_status.HTTP_403_FORBIDDEN) try: node_addon.set_auth(external_account, user_addon.owner) except PermissionsError: raise HTTPError(http_status.HTTP_403_FORBIDDEN) node_addon.save() return { 'result': Serializer().serialize_settings(node_addon, auth.user), 'message': 'Successfully imported access token from profile.', }