def _authorize(self): dbg.info('Request access token from Dropbox') flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = flow.start() # print 'Open auth url:', authorize_url #browser = webdriver.PhantomJS(service_log_path=os.path.join(tempfile.gettempdir(), 'ghostdriver.log')) #browser = webdriver.PhantomJS(service_log_path=os.path.join(tempfile.gettempdir(), 'ghostdriver.log'), service_args=['--ignore-ssl-errors=true', '--ssl-protocol=tlsv1']) # Change to rely on browser print( "We need to authorize access to Dropbox. Please visit the following URL and authorize the access:" ) print(authorize_url) print("") code = raw_input("Input the code you got: ").strip() #code = #raw_input("Enter the authorization code here: ").strip() try: oauth_result = flow.finish(code) with open(self.auth_file, 'w') as file: file.write(oauth_result.access_token + "\n") file.write(oauth_result.user_id + "\n") dbg.info('Authentication successful') return (oauth_result.access_token, oauth_result.user_id) except Exception, e: print('Error: %s' % (e, )) return
def createDropBoxAuth(path): APP_KEY = DROPBOX_APPKEY # Removed key access for privacy, you can easily create you own DropBox application file for auth creds. APP_SECRET = DROPBOX_APPSECRET auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print('Error: %s' % (e, )) exit(1) token = oauth_result.access_token try: with open(path, 'wb') as filetoken: pickle.dump(token, filetoken) print("Successfully set up DropBox token!") except: print("Invalid path") return
def connect_db(): APP_KEY = "8b7lcrabzxhy9uz" APP_SECRET = "5xakxbps2e8a2dt" auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() print("1. Go to(already coppied in Ctrl + C): " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") pyperclip.copy(authorize_url) yeah = 0 while yeah != 1: try: auth_code = input("Enter the authorization code here: \n").strip() oauth_result = auth_flow.finish(auth_code) yeah = 1 except Exception: print("La has liado parda, vuelve a empezar\n") dbx = dropbox.Dropbox(oauth_result.access_token) print(dbx.users_get_current_account()) return oauth_result.access_token
def access_OauthAutomatic(): global token driver = webdriver.Ie('IEDriverServer') auth_flow = DropboxOAuth2FlowNoRedirect('b84tcu1f1ctkwpw', '2rye81pkwjfuf85') authorize_url = auth_flow.start() driver.get(authorize_url) auth_login = input('Informe login: '******'Informe senha: ') driver.find_element_by_xpath("//input[@name='login_email']").send_keys(auth_login) driver.find_element_by_xpath("//input[@name='login_password']").send_keys(auth_senha) driver.find_element_by_class_name('login-button').click() time.sleep(20) driver.find_element_by_id('warning-button-continue').click() time.sleep(10) driver.find_element_by_xpath("//button[@name='allow_access']").click() time.sleep(5) auth_code = driver.find_element_by_xpath("//input[@class='auth-box']").get_attribute('data-token') try: oauth_result = auth_flow.finish(auth_code) token = dropbox.Dropbox(oauth_result.access_token) driver.quit() print("200:success") except Exception as err: print('500: {}'.format(err))
def oauth_init(APP_KEY, APP_SECRET): auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print('Error: %s' % (e, )) exit(1) with dropbox.Dropbox(oauth2_access_token=oauth_result.access_token) as dbx: dbx.users_get_current_account() print("Successfully set up client!") with open("config.py", "r") as file: data = file.readlines() file.close() data[3] = 'oauth_result = \'' + oauth_result.access_token + '\'\n' with open("config.py", "w") as f: f.writelines(data) f.close()
def __init__(self): self.auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) self.authorize_url = self.auth_flow.start() self.dbx = None self.tree = Tree() self.path_actual = '' # Si el string es vacĂo estamos en el root
def setupoauth2file(code): auth_flow = DropboxOAuth2FlowNoRedirect("c02irh2snxzphs5", "p3fdzx55ae539q8") auth_flow.start() code = auth_flow.finish(code) with open("./code.ini","w") as file: file.write(code.access_token)
def dropbox_oauth_flow(): """Sets up flow for user auth via Dropbox OAuth Returns: redirect_url: The URL where the user has to go to in order to verify themselves """ auth_flow = DropboxOAuth2FlowNoRedirect(dropbox_app_key, consumer_secret=dropbox_app_secret, token_access_type='offline', scope=SCOPES) auth_url = auth_flow.start() return auth_url
def __init__(self, token): self.client = None self.app_key = 'iok20w90lywwjng' self.app_secret = '1ip2creb4oxs83t' self.app_type = 'app_folder' self.flow = DropboxOAuth2FlowNoRedirect(self.app_key, self.app_secret) self.authorize_url = self.flow.start() if (token != ""): {self.conectar(token)}
def getAccount(num): num = str(num) if os.path.exists('dropbox/token' + num + '.txt'): token = open('dropbox/token' + num + '.txt', 'r').read().strip('\n') return dropbox.Dropbox(token) else: app_key = open('dropbox/app_key.txt').read() app_secret = open('dropbox/app_secret.txt').read() flow = DropboxOAuth2FlowNoRedirect(app_key, app_secret) url = flow.start() webbrowser.open(url) return flow
def __init__(self): super().__init__() self.setupUi(self) self.auth_flow = DropboxOAuth2FlowNoRedirect("o03x4f6y9dw5hsc", "zgt1fwtne4de6ed") self.authorize_url = self.auth_flow.start() url = QtCore.QUrl(self.authorize_url) self.dbxauth.load(url) self.errorwidget = ErrorWidget() #buttons connection self.loginButton.clicked.connect(self.init_dbx)
def dbx_token(self): APP_KEY = "cep4re0edd3vsmp" APP_SECRET = "7029x3nth5mykw9" auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print('Error: %s' % (e,)) self.TOKEN = oauth_result.access_token
def access_Oauth(): global token auth_flow = DropboxOAuth2FlowNoRedirect('b84tcu1f1ctkwpw', '2rye81pkwjfuf85') authorize_url = auth_flow.start() webbrowser.open(authorize_url, new=2) auth_code = input("202: ").strip() try: oauth_result = auth_flow.finish(auth_code) token = dropbox.Dropbox(oauth_result.access_token) print("200:success") except Exception as err: print('500: {}'.format(err))
def handle_noargs(self, *args, **options): auth_flow = DropboxOAuth2FlowNoRedirect(CONSUMER_KEY, CONSUMER_SECRET) authorize_url = auth_flow.start() self.stdout.write('1. Go to: {}'.format(authorize_url)) self.stdout.write('2. Click "Allow" (you might have to log in first).') self.stdout.write('3. Copy the authorization code.') auth_code = raw_input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) self.stdout.write("DROPBOX_ACCESS_TOKEN = '{}'".format( oauth_result.access_token)) except Exception as e: raise CommandError('Error: {}'.format(e))
def dbox_setup(config): print(""" Authorizing CFS_Manager to access your Dropbox account will require your webbrowser. An authorization page will be opened on Dropbox's website. You'll need to click 'Allow', then paste the code here. """) cont = input("To continue, enter any letter: ") if cont: auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() webbrowser.open(authorize_url) auth_code = input("Enter the authorization code here: ").strip().strip( '"').strip("'").strip() config.write('Dropbox ::: ' + auth_code + '\n') else: print("Dropbox setup cancelled")
def authorize(self): flow = DropboxOAuth2FlowNoRedirect(self.auth_cred['client_id'], self.auth_cred['client_secret']) auth_url = flow.start() print "1. Go to: " + auth_url print "2. Click \"Allow\" (you might have to log in first)." print "3. Copy the authorization code." auth_code = raw_input("Enter the authorization code here: ").strip() try: oauth_result = flow.finish(auth_code) self.credentials = oauth_result except Exception as e: print "Following error raised while authentication: " + str(e) return self.credentials
def get_dropbox_auth_token(code): """Veryfies the authorization code and generates access token for the user Args: code: Authorization code sent by the user Returns: access_token: Access token for the user """ auth_flow = DropboxOAuth2FlowNoRedirect(dropbox_app_key, consumer_secret=dropbox_app_secret, token_access_type='offline', scope=SCOPES) auth_result = auth_flow.finish(code) token_json = json.dumps({ "oauth2_access_token": auth_result.access_token, "oauth2_refresh_token": auth_result.refresh_token }) return token_json
def authorize_user(): auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print('Error: {}'.format(e)) exit(1) global dbx dbx = dropbox.Dropbox(oauth_result.access_token)
def login(): global settings # Writes auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() webbrowser.open(authorize_url) auth_code = simpledialog.askstring( "Log Into MinecraftVC", "Please log into dropbox in the link opened, authorize this app, and paste the " "code into the text field to log into MinecraftVC.").strip() try: oauth_result = auth_flow.finish(auth_code) except: return "Error logging in, are you sure you typed in the code correctly?" settings["OAUTH"] = oauth_result return "Logged In"
def get_new_auth_token(self): # Run the dropbox OAuth Flow to get the user's OAuth Token. auth_flow = DropboxOAuth2FlowNoRedirect(config.dropbox.app_key, config.dropbox.app_secret) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print('Error: %s' % (e, )) return config.write_to_user_config('dropbox', 'api_token', oauth_result.access_token) return oauth_result.access_token
def handle(self, *args, **options): if not (CONSUMER_KEY and CONSUMER_SECRET): raise ImproperlyConfigured("To use this tool you have to set " "'settings.DROPBOX_CONSUMER_KEY' and " "'settings.DROPBOX_CONSUMER_SECRET'.") auth_flow = DropboxOAuth2FlowNoRedirect(CONSUMER_KEY, CONSUMER_SECRET) authorize_url = auth_flow.start() self.stdout.write('1. Go to: {}'.format(authorize_url)) self.stdout.write('2. Click "Allow" (you might have to log in first).') self.stdout.write('3. Copy the authorization code.') auth_code = raw_input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) token = oauth_result.access_token self.stdout.write("DROPBOX_ACCESS_TOKEN = '{}'".format(token)) except Exception as e: raise CommandError('Error: {}'.format(e))
def credentials(auth_code=None): credentials = os.path.join('credentials/dropbox', str(next_drive_id(DBox))) if auth_code: oauth_result = None try: oauth_result = DBox.auth_flow.finish(auth_code) except: return 'failure', None else: os.mkdir(credentials) with open(os.path.join(credentials, 'credentials.txt'), 'a+') as file: file.write(oauth_result.access_token) return 'success', credentials else: DBox.auth_flow = DropboxOAuth2FlowNoRedirect( 'xflfxng1226db2t', 'rnzxajzd6hq04d6') auth_url = DBox.auth_flow.start() return 'pending', auth_url
def link_account(self): """Link user's Dropbox storage, in case of failure return False, indicating that the error occurred.""" auth_flow = DropboxOAuth2FlowNoRedirect(self._APP_KEY, self._APP_SECRET) authorize_url = auth_flow.start() print("You will be redirected to the authorization page.") print("Copy the authorization code and paste it to the terminal window.") time.sleep(3) webbrowser.open(authorize_url) auth_code = input("Enter the code: ").strip() try: oauth_result = auth_flow.finish(auth_code) self._access_token = oauth_result.access_token self._dbx_user_account = Dropbox(self._access_token) return True except: print( "An error occurred while connecting Dropbox storage.\nPlease, check you internet connection and try again.") return False
def login_dropbox(self): """ Authorize dropbox using Oauth2 Follow instructions and authorise your dropbox account to app. """ APP_KEY = "0ntzsx9e42ezvjp" APP_SECRET = "k9erv6t8zcx7jto" auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print('2. Click "Allow" (you might have to log in first).') print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print(f"Error: {e}") return oauth_result
def get_refresh_token(self): refresh_token = None auth_flow = DropboxOAuth2FlowNoRedirect(self._app_key, use_pkce=True, token_access_type='offline') authorize_url = auth_flow.start() print() print('1. Go to: ' + authorize_url) print('2. Click "Allow" (you might have to log in first).') print('3. Copy the authorization code.') auth_code = input('Enter the authorization code here: ').strip() try: oauth_result = auth_flow.finish(auth_code) refresh_token = oauth_result.refresh_token except Exception as e: print('Error: %s' % (e, )) return refresh_token
def start(): """Initializes the Dropbox object that acts as a filesystem abstraction""" with open('system_config.txt', 'r') as config: #Acquires auth_code from saved file content = config.readlines() for line in content: if 'Dropbox' in line: save = line break auth_code = save.split(':::')[1].strip() try: oauth_result = auth_flow.finish(auth_code) except Exception: auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() webbrowser.open(authorize_url) auth_code = input("Enter the authorization code here: ").strip() update_config(content, save, auth_code) try: oauth_result = auth_flow.finish(auth_code) except Exception: pass return Dropbox(oauth_result.access_token)
def add_token(config_file): key = config_file['APP_CREDS']['app_key'] secret_key = config_file['APP_CREDS']['secret_app_key'] auth_flow = DropboxOAuth2FlowNoRedirect(key, secret_key) authorize_url = auth_flow.start() print('1. Go to: ' + authorize_url) print('2. Click "Allow" (you might have to log in first).') print('3. Copy the authorization code.') auth_code = input('Enter the authorization code here: ').strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print('Error: ', e) account_info = Dropbox(oauth_result.access_token).users_get_current_account() config_file['USER_CREDENTIALS'] = { 'user_name': account_info.name.display_name, 'email': account_info.email, 'account_id': account_info.account_id, 'oauth_key': oauth_result.access_token } with open(config.CREDS_FILE, 'w') as f: config_file.write(f) return oauth_result.access_token
def _get_refresh_token(self, token_path): refresh_token = '' if os.path.exists(token_path): with open(token_path, 'r') as f_dsc: refresh_token = f_dsc.read() if not refresh_token: auth_flow = DropboxOAuth2FlowNoRedirect( self._app_key, use_pkce=True, token_access_type='offline') authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception: logger.exception('Could not get token!') else: refresh_token = oauth_result.refresh_token return refresh_token
def main(): error = False if len(argv) < 4: print("Missing arguments. Usage:", argv[0], "<app secret>", \ "<access token> <command> [<args>]") exit(0) global APP_SECRET, ACCESS_TOKEN APP_SECRET = argv[1] access_token_string = argv[2] command = argv[3] # if access token has ben specified, set it if access_token_string != "none": ACCESS_TOKEN = access_token_string try: if command == "authorize_url": auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) print(":URL:" + get_authorize_url(auth_flow) + ":") elif command == "create_access_token": if len(argv) >= 5: auth_token_string = argv[4] else: print("Error:Auth token not specified in get_access_token()") exit(0) auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) print(":Access token:" + get_access_token(auth_flow, auth_token_string) + ":") elif command == "user_name": dbx = Dropbox(ACCESS_TOKEN) print(":User:"******":") elif command == "upload_file": if len(argv) < 6: print("Error:Arguments missing in upload_file()") exit(0) src = argv[4] dest = argv[5] dbx = Dropbox(ACCESS_TOKEN) response = upload_file(dbx, src, dest) print(response) elif command == "upload_file_chunked": if len(argv) < 6: print("Error:Arguments missing in upload_file_chunked()") exit(0) src = argv[4] dest = argv[5] dbx = Dropbox(ACCESS_TOKEN) response = upload_file_chunked(dbx, src, dest) print(response) elif command == "download_file": if len(argv) < 6: print("Error:Arguments missing in download_file()") exit(0) src = argv[4] dest = argv[5] dbx = Dropbox(ACCESS_TOKEN) response = download_file(dbx, src, dest) print(response) elif command == "delete_file": if len(argv) < 5: print("Error:Arguments missing in delete_file()") exit(0) dbx = Dropbox(ACCESS_TOKEN) delete_file(dbx, argv[4]) print("Delete:OK") else: print("Error:Invalid command") except Exception as e: print("Error:" + str(e)) exit(0)
import pandas as pd import dropbox from tqdm import tqdm from dropbox import DropboxOAuth2FlowNoRedirect ''' This sets up a dropbox OAuthed client ''' APP_KEY = 'xxx' APP_SECRET = 'xxx' auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET) authorize_url = auth_flow.start() print("1. Go to: " + authorize_url) print("2. Click \"Allow\" (you might have to log in first).") print("3. Copy the authorization code.") auth_code = input("Enter the authorization code here: ").strip() try: oauth_result = auth_flow.finish(auth_code) except Exception as e: print('Error: %s' % (e, )) exit(1) with dropbox.Dropbox(oauth2_access_token=oauth_result.access_token) as dbx: dbx.users_get_current_account() print("Successfully set up client!") ''' This sets up the varibles needed '''