def disconnect(request): if request.method == 'POST': logger.info('Disconnect Dropbox.com requested by user...') try: dropbox_token = DropboxUserToken.objects.get(user=request.user) dropbox = Dropbox(dropbox_token.access_token) dropbox.auth_token_revoke() dropbox_user_token = request.user.dropbox_user_token dropbox_user_token.delete() except AuthError: dropbox_user_token = request.user.dropbox_user_token dropbox_user_token.delete() except DropboxUserToken.DoesNotExist: logger.warn('Disconnect Dropbox; DropboxUserToken does not exist.', extra={'user': request.user}) except: logger.error('Disconnect Dropbox; DropboxUserToken delete error.', extra={'user': request.user}) messages.success( request, 'Your Dropbox.com account has been disconnected from DesignSafe.') return HttpResponseRedirect(reverse('dropbox_integration:index')) return render(request, 'designsafe/apps/dropbox_integration/disconnect.html')
def revoke_remote_oauth_access(self, external_account): """Overrides default behavior during external_account deactivation. Tells Dropbox to remove the grant for the OSF associated with this account. """ client = Dropbox(external_account.oauth_key) try: client.auth_token_revoke() except DropboxException: pass
def revoke(request): try: integration = Integration.objects.get(user=request.user) db = Dropbox(integration.access_token) db.auth_token_revoke() integration.delete() except Integration.DoesNotExist: pass return HttpResponseRedirect(reverse('index'))