コード例 #1
0
ファイル: syncer.py プロジェクト: hglkrijger/psync
    def new_session(self, account):
        redirect_uri = self.config.redirect_uri
        client_secret = self.config.client_secret
        client_id = self.config.client_id
        session_file = self.config.session_file(account)

        logger.info('loaded secrets successfully')

        if self.is_pretend:
            logger.info('authenticate account "%s" for app %s at %s', account,
                        client_id, redirect_uri)
            return

        client = onedrivesdk.get_default_client(client_id=client_id,
                                                scopes=scopes)
        auth_url = client.auth_provider.get_auth_url(redirect_uri)
        logger.info('authenticating account "%s" via the browser...', account)
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
        client.auth_provider.authenticate(code, redirect_uri, client_secret)
        client.auth_provider.save_session(path=session_file)

        if os.path.exists(session_file):
            logger.info('session saved to %s for account %s', session_file,
                        account)
        else:
            logger.warn('expected session file not found [%s]', session_file)
コード例 #2
0
ファイル: odc.py プロジェクト: JunpeiAnzai/odc
def main():
    redirect_uri = "http://localhost:8080/"
    client_secret = "tzUNLG6DdGydHriTGawVVg4"

    client = onedrivesdk.get_default_client(
        client_id='5d866328-ad7e-4414-9bc9-df1e47004d41',
        scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

    client.auth_provider.authenticate(code, redirect_uri, client_secret)

    # watchdog
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    path = sys.argv[1] if len(sys.argv) > 1 else '.'
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
コード例 #3
0
def main():
    redirect_uri = 'http://localhost:8080/'
    client_id = '2d7760a0-1410-4a1f-a995-eaf1bb10a4a1'
    client_secret = 'ntqgJGQ981{=#tqwKLHQ42#'
    scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

    client = onedrivesdk.get_default_client(client_id=client_id, scopes=scopes)
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    #this will block until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    client.auth_provider.authenticate(code, redirect_uri, client_secret)
    item_id = "root"
    copy_item_ids = None
    action = 0

    files = [f for f in os.listdir('.') if os.path.isfile(f)]
    merged = []
    for f in files:
        filename, ext = os.path.splitext(f)
        if ext == '.csv':
            read = pd.read_csv(f)
            merged.append(read)

    result = pd.concat(merged, sort=False, ignore_index=True)
    result.to_excel('merged.xlsx')

    client.item(id=item_id).children['merged.xlsx'].upload(
        'D:\Workspace_git\onedrive-sdk-python\hackathon2018\merged.xlsx')
コード例 #4
0
ファイル: AccessOneDrive.py プロジェクト: funmu/katka
	def Connect( self, clientId, redirectUri, clientSecret):

		print( "\t  a. Creating a client object");
		self.client = onedrivesdk.get_default_client(client_id=clientId,
		                                        scopes=[
		                                        #	'wl.signin',
		                                        #   'wl.offline_access',
												#	"offline_access",
												 'onedrive.readwrite'])

		print( "\t  b. Getting an authorization URL");
		auth_url = self.client.auth_provider.get_auth_url(redirectUri);
		# print( auth_url);

		#this will block until we have the code

		print( "\t  c. Getting the Auth code");
		code = GetAuthCodeServer.get_auth_code(auth_url, redirectUri);
		# print(code);

		print( "\t  d. Complete the authentication process");
		self.client.auth_provider.authenticate(code, redirectUri, clientSecret);
		# print("\t authentication complete ...");

		print( "\t  e. Load up the children for root node after connection");
		rootItem = self.idPathDirectory["/"];
		allItems = self.GetAllItemsForId( rootItem.id, "");
		rootItem.children = allItems;

		return;
コード例 #5
0
    def start_connection(self):
        client_id = self.app_credentials['client_id']

        self.client = onedrivesdk.get_default_client(client_id=client_id,
                                                     scopes=self.SCOPES)
        auth_url = self.client.auth_provider.get_auth_url(
            self.get_oauth_redirect_url())
        return auth_url
コード例 #6
0
 def __init__(self, client_id, client_secret, redirect_uri):
     self.client_id = client_id
     self.client_secret = client_secret
     self.redirect_uri = redirect_uri
     self.api_base_url = 'https://api.onedrive.com/v1.0/'
     self.scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
     self.client = onedrivesdk.get_default_client(client_id=self.client_id,
                                                  scopes=self.scopes)
コード例 #7
0
 def login(self, redirect_uri, client_id, client_secret):
     scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
     client = onedrivesdk.get_default_client(client_id=client_id,
                                             scopes=scopes)
     auth_url = client.auth_provider.get_auth_url(redirect_uri)
     code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
     client.auth_provider.authenticate(code, redirect_uri, client_secret)
     self.client = client
     return True
コード例 #8
0
def get_onedrive_handle(session_path=None):
    """
    Sign into Onedrive. 
    Return a session proxy on success
    Return None on error
    """
    global RELOAD_DRIVE, ONEDRIVE_HANDLE

    assert CLIENT_ID
    assert CLIENT_SECRET
    assert REDIRECT_URL

    if RELOAD_DRIVE:
        RELOAD_DRIVE = False
        ONEDRIVE_HANDLE = None

    if ONEDRIVE_HANDLE is not None:
        return ONEDRIVE_HANDLE

    if session_path is None:
        assert SESSION_SAVE_PATH
        session_path = SESSION_SAVE_PATH

    client = onedrivesdk.get_default_client(client_id=CLIENT_ID,
                                            scopes=CLIENT_SCOPES)
    if os.path.exists(session_path):
        # load session
        log.debug("Load saved session")
        client.auth_provider.load_session(path=session_path)
        client.auth_provider.refresh_token()

    else:
        dirp = os.path.dirname(session_path)
        if not os.path.exists(dirp):
            try:
                os.makedirs(dirp)
                os.chmod(dirp, 0700)
            except Exception as e:
                if DEBUG:
                    log.exception(e)

                log.error("Failed to make directories to store session")
                return None

        # log in
        auth_url = client.auth_provider.get_auth_url(REDIRECT_URL)

        code = GetAuthCodeServer.get_auth_code(auth_url, REDIRECT_URL)
        client.auth_provider.authenticate(code, REDIRECT_URL, CLIENT_SECRET)

        # save for future user
        client.auth_provider.save_session(path=session_path)

    ONEDRIVE_HANDLE = client
    return client
コード例 #9
0
def auth():
    # authentication
    redirect_uri = 'http://localhost:8080/'
    client_secret = settings.CLIENT_SECRET
    scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
    client = onedrivesdk.get_default_client(
        client_id=settings.CLIENT_ID, scopes=scopes)
    auth_url = client.auth_provider.get_auth_url(redirect_uri)
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    client.auth_provider.authenticate(code, redirect_uri, client_secret)
    return client
コード例 #10
0
def get_onedrive_handle(session_path=None):
    """
    Sign into Onedrive. 
    Return a session proxy on success
    Return None on error
    """
    global RELOAD_DRIVE, ONEDRIVE_HANDLE

    assert CLIENT_ID
    assert CLIENT_SECRET
    assert REDIRECT_URL

    if RELOAD_DRIVE:
        RELOAD_DRIVE = False
        ONEDRIVE_HANDLE = None

    if ONEDRIVE_HANDLE is not None:
        return ONEDRIVE_HANDLE

    if session_path is None:
        assert SESSION_SAVE_PATH
        session_path = SESSION_SAVE_PATH

    client = onedrivesdk.get_default_client(client_id=CLIENT_ID, scopes=CLIENT_SCOPES)
    if os.path.exists(session_path):
        # load session 
        log.debug("Load saved session")
        client.auth_provider.load_session(path=session_path)
        client.auth_provider.refresh_token()

    else:
        dirp = os.path.dirname(session_path)
        if not os.path.exists(dirp):
            try:
                os.makedirs(dirp)
                os.chmod(dirp, 0700)
            except Exception as e:
                if DEBUG:
                    log.exception(e)

                log.error("Failed to make directories to store session")
                return None

        # log in
        auth_url = client.auth_provider.get_auth_url(REDIRECT_URL)

        code = GetAuthCodeServer.get_auth_code(auth_url, REDIRECT_URL)
        client.auth_provider.authenticate(code, REDIRECT_URL, CLIENT_SECRET)

        # save for future user 
        client.auth_provider.save_session(path=session_path)

    ONEDRIVE_HANDLE = client
    return client
コード例 #11
0
def authen(client_secret, client_id, redirect_uri):
    # Authentication
    client = onedrivesdk.get_default_client(client_id,
                                            scopes=['wl.signin',
                                                    'wl.offline_access',
                                                    'onedrive.readwrite'])

    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    #this will block until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    client.auth_provider.authenticate(code, redirect_uri, client_secret)
    return client
コード例 #12
0
ファイル: oneDrive_IO.py プロジェクト: gary258796/stockPython
def getService():
    redirect_uri = 'http://localhost:8080/'
    client_secret = 'zuinSN683;%]xbrINSTY51#'
    client_id = '09ec3860-34c1-4ceb-930e-30beb4de49a7'
    scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
    client = onedrivesdk.get_default_client(
        client_id='09ec3860-34c1-4ceb-930e-30beb4de49a7', scopes=scopes)
    auth_url = client.auth_provider.get_auth_url(redirect_uri)
    # this will block until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    client.auth_provider.authenticate(code, redirect_uri, client_secret)

    return client
コード例 #13
0
def ConnectOneDrive():
    client = onedrivesdk.get_default_client(client_id=onedriveconfig.CLIENT_ID,
                                            scopes=onedriveconfig.SCOPES)
    auth_url = client.auth_provider.get_auth_url(onedriveconfig.REDIRECT_URI)
    # Block thread until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url,
                                           onedriveconfig.REDIRECT_URI)
    # Finally, authenticate!
    client.auth_provider.authenticate(code, onedriveconfig.REDIRECT_URI,
                                      onedriveconfig.CLIENT_SECRET)
    # Save the session for later
    # client.auth_provider.save_session()
    return client
コード例 #14
0
def onedrive_example_auth():
    redirect_uri = "http://localhost:8080/"
    client_secret = "BqaTYqI0XI7wDKcnJ5i3MvLwGcVsaMVM"

    client = onedrivesdk.get_default_client(
        client_id='00000000481695BB',
        scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    # Block thread until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    # Finally, authenticate!
    client.auth_provider.authenticate(code, redirect_uri, client_secret)
コード例 #15
0
def init_onedrive():
    redirect_uri = "https://login.live.com/oauth20_desktop.srf"
    client_id, client_secret = ut.getUserData(path, 'APIsecret')

    client = onedrivesdk.get_default_client(
        client_id=client_id,
        scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    user_name, password = ut.getUserData(path, 'onedrive')
    code = get_token(user_name, password, auth_url)

    client.auth_provider.authenticate(code, redirect_uri, client_secret)
    return client
コード例 #16
0
ファイル: onedrive_lite.py プロジェクト: yehouhou/tools
def main():

    # authentiicate
    redirect_uri = "http://localhost:8080/"
    client_secret = "BqaTYqI0XI7wDKcnJ5i3MvLwGcVsaMVM"

    client = onedrivesdk.get_default_client(
        client_id='00000000481695BB',
        scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    client.auth_provider.authenticate(code, redirect_uri, client_secret)

    while True:
        print("")
        items = client.item(id="root").children.get()
        count = 0
        # print items in root directory
        for count, item in enumerate(items):
            print("{} {}".format(
                count + 1,
                item.name if item.folder is None else "/" + item.name))

        selected = input(
            "Enter an item id to download, or enter U to upload, or enter Q to quit: "
        )

        if selected == 'Q':
            exit()

        elif selected == 'U':
            try:
                upload(client, "root")
                print("Successfully uploaded.")
            except Exception as e:
                print(e)

        else:
            selected = int(selected)
            if items[selected - 1].folder is None:
                try:
                    download(client, items[selected - 1].id,
                             items[selected - 1].name)
                    print("Successfully downloaded.")
                except Exception as e:
                    print(e)
            else:
                print("Error: Can't download a folder.")
コード例 #17
0
ファイル: onedriver.py プロジェクト: carolus-rex/onedriver
    def authenticator(self):
        self.get_local_auth_data()

        client = onedrivesdk.get_default_client(client_id=self.client_id,
                                                scopes=scopes)

        auth_url = client.auth_provider.get_auth_url(redirect_uri)

        # this will block until we have the code
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

        client.auth_provider.authenticate(code, redirect_uri,
                                          self.client_secret)

        return client
コード例 #18
0
ファイル: pyonedrive.py プロジェクト: rwecho/hellolinux
    def __init__(self,):
        
        self.pattern = re.compile(r'20\d{2}/\d{2}')
        self.path = u"/文档/我的笔记"
        self.client_secret = "PTjISDwkedG1ZS3FVteB7PMvX3SbFX0U"
        self.client_id = "000000004C17D062"
        self.client = onedrivesdk.get_default_client(client_id=self.client_id,
                                        scopes=['wl.signin',
                                                'wl.offline_access',
                                                'onedrive.readwrite'])

        reload(sys)                      # reload then setdefaultencoding 
        sys.setdefaultencoding('utf-8')  # set 'utf-8'

        self.client.auth_provider.load_session()
コード例 #19
0
ファイル: demo.py プロジェクト: mhxie/Recloud
def main():
    redirect_uri = "http://localhost:8080/"
    client_secret = "bBYGVLQKqLL7NJMZzZQP0Z1"

    client = onedrivesdk.get_default_client(
        client_id='7b9de733-5078-4275-9ded-ea44fb9368d6',
        scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

    client.auth_provider.authenticate(code, redirect_uri, client_secret)

    root = client.item(id="root").get()

    listItemsInFolder(client, '', root)
コード例 #20
0
def main():
    redirect_uri = "http://localhost:8080/"
    client_secret = "BqaTYqI0XI7wDKcnJ5i3MvLwGcVsaMVM"

    client = onedrivesdk.get_default_client(
        client_id='00000000481695BB',
        scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

    client.auth_provider.authenticate(code, redirect_uri, client_secret)

    root = client.item(id="root").get()

    listItemsInFolder(client, '', root)
コード例 #21
0
ファイル: syncer.py プロジェクト: hglkrijger/psync
    def refresh_session(self, account):
        client_id = self.config.client_id
        session_file = self.config.session_file(account)

        logger.info('loading session for account %s, app %s %s', account,
                    client_id, '[dry-run]' if self.is_pretend else '')
        client = onedrivesdk.get_default_client(client_id=client_id,
                                                scopes=scopes)

        if not self.is_pretend:
            client.auth_provider.load_session(path=session_file)
            client.auth_provider.refresh_token()

        logger.info('token refreshed for %s', account)

        return client
コード例 #22
0
    def onedrive_auth_own_app_webserver():
        redirect_uri = 'http://localhost:5000/login/authorized'
        client_secret = 'bnQV76$%^inqsaDBRKG479#'
        scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

        client = onedrivesdk.get_default_client(
            client_id='c8e4b648-3fc8-4948-8c59-0b14d8972582', scopes=scopes)

        auth_url = client.auth_provider.get_auth_url(redirect_uri)

        # this will block until we have the code
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

        client.auth_provider.authenticate(code, redirect_uri, client_secret)

        client.auth_provider.save_session()
コード例 #23
0
def main(onedrive_location, local_location):

	# Setup OneDrive
	with open("client_id.txt") as myfile:
		client_id = myfile.readline().strip()
	client = onedrivesdk.get_default_client(client_id=client_id,
											scopes=['wl.signin',
											'wl.offline_access',
											'onedrive.readwrite'])

	client.auth_provider.load_session(path="client_code.data")

	folder_id = get_folder_id(client, onedrive_location)

	# Upload any files that are ready for it.
	for fpath in get_new_files (local_location):
		onedrive_upload(client, folder_id, fpath)
コード例 #24
0
    def connect(self):
        try:
            redirect_uri = "http://localhost:8080/"
            client_id = self.app_key_ac
            client_secret = self.app_secret_ac
            self.client = onedrivesdk.get_default_client(client_id=client_id,
                                                scopes=['wl.signin',
                                                        'wl.offline_access',
                                                        'onedrive.readwrite'])
            auth_url = self.client.auth_provider.get_auth_url(redirect_uri)

            code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
            self.client.auth_provider.authenticate(code, redirect_uri, client_secret)
            return True
        except Exception:
            print('error connecting to the server: OneDive')
            return False
コード例 #25
0
def auto_setup(): 

    redirect_uri = 'http://localhost:5658/'
    client_secret = 'mzlYU32347(+yybjPKKSF*{'
    scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

    client = onedrivesdk.get_default_client(
        client_id='339f450f-3701-42ef-bcaa-a0b35a369c18', scopes=scopes)

    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    #this will block until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

    client.auth_provider.authenticate(code, redirect_uri, client_secret)

    return client
コード例 #26
0
    def get_auth(self):
        """ do authorization """
        self.client = get_default_client(
            client_id=self.client_id,
            scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])
        if os.path.exists(os.path.join(HOMEDIR, '.onedrive_session.pkl')):
            with open(os.path.join(HOMEDIR, '.onedrive_session.pkl'), 'rb') as pfile:
                self.client.auth_provider._session = pickle.load(pfile)
        else:
            auth_url = \
                self.client.auth_provider.get_auth_url(self.redirect_uri)
            code = get_auth_code(auth_url, self.redirect_uri)
            self.client.auth_provider.authenticate(code, self.redirect_uri, self.client_secret)
            with open(os.path.join(HOMEDIR, '.onedrive_session.pkl'), 'wb') as pfile:
                pickle.dump(
                    self.client.auth_provider._session, pfile, protocol=pickle.HIGHEST_PROTOCOL)

        return self.client
コード例 #27
0
 def try_auth(self):
     redirect_uri = 'http://localhost:8080/'
     scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
     try:
         api_end = onedrivesdk.get_default_client(client_id=self.client_id, scopes=scopes)
         auth_url = api_end.auth_provider.get_auth_url(redirect_uri)
         #this will block until we have the code
         # TODO: Check if this code can be stored and reused
         # TODO: Will also need a timeout in case the user closes the webpage
         try:
             code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
             api_end.auth_provider.authenticate(code, redirect_uri, token)
             code = None
         except (KeyboardInterrupt) as e:
             raise e
         self.api_end = api_end
     except Exception:
         raise AuthenticationError
コード例 #28
0
ファイル: app.py プロジェクト: Velaa98/CloudsManage
def upload():
	return render_template("upload.html",uploaded=False)
	if request.method == "POST":
		redirect_uri = 'https://cloudsmanage.herokuapp.com/upload'
		client_secret = os.environ['consumer_secret']
		scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']
		client = onedrivesdk.get_default_client(client_id=os.environ['consumer_key'], scopes=scopes)
		auth_url = client.auth_provider.get_auth_url(redirect_uri)
		code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
		client.auth_provider.authenticate(code, redirect_uri, client_secret)
		file = request.files['file']
		filename = secure_filename(file.filename)
		file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
		returned_item = client.item(drive='me', id='root').children[filename].upload('./upload/%s'%(file.filename))
		
		return render_template("upload.html",uploaded=True)
	else:
		return render_template("upload.html",uploaded=False)
コード例 #29
0
ファイル: setup.py プロジェクト: nksen/backup-to-onedrive
def authenticate():
    import onedrivesdk
    from onedrivesdk.helpers import GetAuthCodeServer

    redirect_uri = 'http://localhost:5000/login/authorized'
    client_secret = 'leyOGUMS23}ulglTR392(;?'
    scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

    client = onedrivesdk.get_default_client(
        client_id='325892db-391d-4ac1-bbd2-86f6f085f105', scopes=scopes)

    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    # this will block until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

    client.auth_provider.authenticate(code, redirect_uri, client_secret)
    print("Success")
    return client
コード例 #30
0
    def __save_credentials(self, session_file):
        # api_base_url = self.__config.get('onedrive', 'onedrive.api_base_url')
        redirect_uri = 'http://localhost:8080/'
        client_id = self.__config.get('onedrive', 'onedrive.client_id')
        client_secret = self.__config.get('onedrive', 'onedrive.client_secret')

        client = onedrivesdk.get_default_client(client_id=client_id,
                                                scopes=self.__scopes)

        auth_url = client.auth_provider.get_auth_url(redirect_uri)

        # this will block until we have the code
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

        client.auth_provider.authenticate(code, redirect_uri, client_secret)

        # Save the session for later
        client.auth_provider.save_session(path=session_file)
        log_info('[+] new credentials saved')
コード例 #31
0
ファイル: onedrivedb.py プロジェクト: idanpa/whereismytime
    def __init__(self):
        # Authentication:
        self.client = onedrivesdk.get_default_client(client_id=WMT_CLIENT_ID,
                                                     scopes=scopes)

        self.authenticate()

        # TODO: maybe better hide it? use temp file or something? maybe we can connect sqlite directly to onedrive callbacks (we can't)
        # maybe it's faster to check if we have the latest update already downloaded?
        local_file_path = os.path.join(getuserdir(), 'wmtdb.db')
        self.db_file_item = self.client.item(drive='me',
                                             path=ONEDRIVEDB_WMT_DB_PATH)
        try:
            self.db_file_item.download(local_file_path)
        # if DB doesn't exist, we wil create it in parent init:
        except onedrivesdk.error.OneDriveError:
            pass

        super().__init__(local_file_path)
コード例 #32
0
def main():
    redirect_uri = "http://localhost:8080/"

    with open("client_secret.txt") as myfile:
        client_secret = myfile.readline().strip()
    with open("client_id.txt") as myfile:
        client_id = myfile.readline().strip()

    client = onedrivesdk.get_default_client(
        client_id=client_id,
        scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite'])

    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    # Block thread until we have the code

    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    client.auth_provider.authenticate(code, redirect_uri, client_secret)

    client.auth_provider.save_session(path="client_code.data")
コード例 #33
0
    def authenticate(self):

        redirect_uri = "http://localhost:8080/"
        client_secret = "k84Ntgni9H86TfiDAgdaSyv"

        self.client = onedrivesdk.get_default_client(client_id='0000000048197E3B',
                                                scopes=['wl.signin',
                                                        'wl.offline_access',
                                                        'wl.skydrive_update',
                                                        'onedrive.readwrite'])

        auth_url = self.client.auth_provider.get_auth_url(redirect_uri)

        # this will block until we have the code
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

        self.client.auth_provider.authenticate(code, redirect_uri, client_secret)
        self.access_token = self.client.auth_provider._session.access_token

        self.main_folder = self.create_folder("root", "Secure-Cloud")
コード例 #34
0
ファイル: OneDrive.py プロジェクト: TheQueenIsDead/OneDOS
    def login(self):

        with open('./oauth_settings.yml', 'r') as config_file:
            oauth_settings = yaml.safe_load(config_file)

        redirect_uri = oauth_settings['redirect']
        client_secret = oauth_settings['app_secret']
        scopes = ['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

        client = onedrivesdk.get_default_client(
            client_id=oauth_settings['app_id'], scopes=scopes)

        auth_url = client.auth_provider.get_auth_url(redirect_uri)

        # this will block until we have the code
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

        client.auth_provider.authenticate(code, redirect_uri, client_secret)

        return client
コード例 #35
0
ファイル: pub_onedrive.py プロジェクト: 2XL/py_publish
    def _authenticate_with_helper(self):

        redirect_uri = CREDENTIALS_ONEDRIVE["redirect_uri"]
        client_secret = CREDENTIALS_ONEDRIVE["client_secret"]

        self.client = onedrivesdk.get_default_client(
            client_id=CREDENTIALS_ONEDRIVE["client_id"],
            scopes=['wl.signin',
                    'wl.offline_access',
                    'onedrive.readwrite']
        )

        auth_url = self.client.auth_provider.get_auth_url(redirect_uri)
        print "Auth URL: {}".format(auth_url)
        # this will block until we have the code

        code = GetAuthCodeServer.get_auth_code(auth_url=auth_url, redirect_uri=redirect_uri)
        print "Code:     {}".format(code)
        self.client.auth_provider.authenticate(code, redirect_uri, client_secret)

        print "Client Authentication OK"
コード例 #36
0
ファイル: onedrivestuff.py プロジェクト: remko66/remkodrive
    def connect(self):
        try:
            http_provider = onedrivesdk.HttpProvider()
            auth_provider = onedrivesdk.AuthProvider(
                http_provider=http_provider,
                client_id=self.client_id,
                scopes=self.scopes)
            self.client = onedrivesdk.get_default_client(
                client_id=self.client_id, scopes=self.scopes)
            auth_url = self.client.auth_provider.get_auth_url(
                self.redirect_uri)

            # Block thread until we have the code
            code = GetAuthCodeServer.get_auth_code(auth_url, self.redirect_uri)
            if len(code) > 10:
                self.client.auth_provider.authenticate(code, self.redirect_uri,
                                                       self.client_secret)
                self.client.auth_provider.save_session()
                self.isconnected = True
        except:
            print("Unexpected error:", sys.exc_info()[0])
        return self.isconnected
コード例 #37
0
    def _connect(self, _session):
        # to be called with a OneDrive session object or pickle  string
        if type(_session) in [str, unicode]:
            _session = pickle.loads(_session)

        if self.client is None:
            client_id = self.app_credentials['client_id']
            self.client = onedrivesdk.get_default_client(client_id=client_id,
                                                         scopes=self.SCOPES)
        self.client.auth_provider._session = _session

        # get email
        url = "https://apis.live.net/v5.0/me"
        with self.exception_handler():
            req = onedrivesdk.request_base.RequestBase(url, self.client, [])
            req.method = "GET"
            res = req.send()
            assert res.status == 200
            self.email = json.loads(res.content)["emails"]["preferred"]

        self.credential_manager.set_user_credentials(self.__class__, self.uid,
                                                     pickle.dumps(_session))
コード例 #38
0
def auth():
    # get the client secret from our text file which MUST be in same dir as this script - register this https://dev.onedrive.com/app-registration.htm
    client_id_secret_str = open(os.path.dirname(os.path.realpath(sys.argv[0])) + '/client_secret.txt').read()
    client_id_secret = client_id_secret_str.split(':')
    if len(client_id_secret) != 2:
        logging.critical('client_secret.txt not found in this directory, or it\'s invalid. Form should be: client_id:client_secret')
        logging.critical('client_id & client_secret can be obtained by registering the app at https://dev.onedrive.com/app-registration.htm')
        sys.exit()

    client = onedrivesdk.get_default_client(client_id=client_id_secret[0],
                                            scopes=['wl.signin',
                                            'wl.offline_access',
                                            'onedrive.readwrite'])
    
    # load an existing session or load a new one
    if os.path.isfile(get_session_path()):
        logging.info('Loading previous session file from ' + get_session_path())
        client.auth_provider.load_session(path=get_session_path())
        client.auth_provider.refresh_token()
        logging.info('Token refreshed and session loaded')
        return client
    else:
        return auth_new(client, client_id_secret[1])
コード例 #39
0
ファイル: oneDrive.py プロジェクト: 2XL/py_publish
def main():
    redirect_uri = "http://localhost:8080"
    client_secret = "TZhtkvAPY22cZcAmkeXrV3E"

    client = onedrivesdk.get_default_client(client_id='fcb741cb-be05-4349-80d6-cd4f7926d258',
                                            scopes=['wl.signin',
                                                    'wl.offline_access',
                                                    'onedrive.readwrite'])
    auth_url = client.auth_provider.get_auth_url(redirect_uri)

    # Block thread until we have the code
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    # Finally, authenticate!
    client.auth_provider.authenticate(code, redirect_uri, client_secret)
    item_id = "root"
    copy_item_ids = None
    action = 0

    while True:
        items = navigate(client, item_id)
        print("0: UP")
        count = 0
        for count, item in enumerate(items):
            print("{} {}".format(count+1, item.name if item.folder is None else "/"+item.name))

        selected = input("Select item, enter 'C' to copy all, enter 'L' to list changes in current folder: ")

        if selected == "C":
            copy_item_ids = []
            for item in items:
                copy_item_ids.append(item.id)

        elif selected == "L":
            token = input("Enter your token, or nothing if you do not have one: ")
            list_changes(client, item_id, token)

        else:
            selected = int(selected)

            if selected == 0:
                item_id = get_parent_id(client, item_id)
            else:
                action = int(input("Select action: 1:Navigate 2:Rename 3:View Thumbnail 4: Get Sharing Link 5: List Changes 6:Download 7:Upload 8:Delete 9:Copy{}... ".format(" 10: Paste" if copy_item_ids else "")))
                if items[selected-1].folder is None or (action != 6 and action != 1):
                    if action == 1:
                        print("Can't navigate a file")
                    elif action == 2:
                        rename(client, items[selected-1].id)
                    elif action == 3:
                        view_thumbnail(client, items[selected-1].id)
                    elif action == 4:
                        get_sharing_link(client, items[selected-1].id)
                    elif action == 5:
                        token = input("Enter your token, or nothing if you do not have one: ")
                        list_changes(client, items[selected-1].id, token)
                    elif action == 6:
                        download(client, items[selected-1].id)
                    elif action == 7:
                        if item.folder is None:
                            print("You cannot upload to a file")
                        else:
                            upload(client, items[selected-1].id)
                    elif action == 8:
                        delete(client, items[selected-1].id)
                    elif action == 9:
                        copy_item_ids = [items[selected-1].id]
                    elif action == 10 and copy_item_ids:
                        if items[selected-1].folder:
                            paste(client, items[selected-1].id, copy_item_ids)
                        else:
                            print("Can't copy to a file")
                else:
                    item_id = items[selected-1].id
コード例 #40
0
ファイル: onedrive_upload.py プロジェクト: pvineet/birds
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

import onedrivesdk
import requests
from onedrivesdk.helpers import GetAuthCodeServer

driver = webdriver.PhantomJS()
redirect_uri = 'http://localhost:8080/'
client_secret = 'BFNTFFXLfd6niqq8HVbZO8s'
scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

client = onedrivesdk.get_default_client(
    client_id='a4bb6731-f8a5-4137-9322-236390c49d7f', scopes=scopes)

auth_url = client.auth_provider.get_auth_url(redirect_uri)
driver.get(auth_url)
print auth_url
#this will block until we have the code
#code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
#print code
#client.auth_provider.authenticate(code, redirect_uri, client_secret)
コード例 #41
0
ファイル: gui1.py プロジェクト: pecavi/bespin
espGoo=0
    
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
    

for file2 in file_list:

		espGoo+=int(file2.metadata['quotaBytesUsed'])

#conectando con OneDrive-------------------------------
redirect_uri = "http://localhost:8080/"
client_secret = "tLwyKkPS74siASB9DnEKt0C"

client = onedrivesdk.get_default_client(client_id='4490f18b-5c69-4aa4-8694-b84f6e8d9a15',
                                        scopes=['wl.signin',
                                                'wl.offline_access',
                                                'onedrive.readwrite'])
#print client.name
auth_url = client.auth_provider.get_auth_url(redirect_uri)

#this will block until we have the code
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

client.auth_provider.authenticate(code, redirect_uri, client_secret)

items = client.item(id="root").children.get()

item=onedrivesdk.Item()

espOne=0
コード例 #42
0
ファイル: sqlite.py プロジェクト: rwecho/hellolinux
# sql = '''INSERT Or Replace INTO user (id, name, picture, config) VALUES(?, ?,
# ?, ?)'''
# cursor.execute(sql,(id,name,picture,config))
# con.commit()

# con.close()
import sys
print sys.getdefaultencoding()  
import re

redirect_uri = "http://localhost:8001/redirect"
client_secret = "PTjISDwkedG1ZS3FVteB7PMvX3SbFX0U"
client_id = "000000004C17D062"

client = onedrivesdk.get_default_client(client_id=client_id,
                                        scopes=['wl.signin',
                                                'wl.offline_access',
                                                'onedrive.readwrite'])

client.auth_provider.load_session()

reload(sys)                      # reload then setdefaultencoding 
sys.setdefaultencoding('utf-8')  # set 'utf-8'
path = u"/文档/我的笔记"
#print(path)

# r = client.item(drive="me", path=path.encode('utf-8')).children

# print(r._request_url)

# me = r.get()
コード例 #43
0
    foundItem = None
    for item in items:
        if item.name == name:
            foundItem = item
            break
        else:
            pass

    return foundItem

redirect_uri = 'http://localhost:8080/'
client_secret = 'EvMDiYvjSSHZi0hHKjN1gcc'
client_id = 'e0a1b84a-2f92-4e1c-bf75-6ba37fb1c60a'
scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']

client = onedrivesdk.get_default_client(client_id, scopes)
auth_url = client.auth_provider.get_auth_url(redirect_uri)

code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
print code
client.auth_provider.authenticate(code, redirect_uri, client_secret)

item_id = "root"
items = client.item(id = item_id).children.get()

path = "/SmartConn/Backup/Gerrit"
if path is not None and path[0] == '/':
    path = path[1:]
else:
    pass
コード例 #44
0
ファイル: OneDriveDownloader.py プロジェクト: ShaneC/Tools
if (os.path.exists("./" + archive_name + ".zip")):
    raise Exception("Archive name already exists.")

# redirect_uri, client_secret, and client_id can be obtained from:
# http://go.microsoft.com/fwlink/p/?LinkId=193157

redirect_uri = ""
client_secret = ""

if not redirect_uri or not client_secret:
    raise Exception("You must specify a redirect_uri and client_secret.\n" + 
        "You can obtain these from http://go.microsoft.com/fwlink/p/?LinkId=193157.")

client = onedrivesdk.get_default_client(
    client_id='<CLIENT_ID>',
    scopes=['wl.signin', 'onedrive.readonly'])

auth_url = client.auth_provider.get_auth_url(redirect_uri)

# This will block until we have the code
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

client.auth_provider.authenticate(code, redirect_uri, client_secret)

root_folder = client.item(drive="me", id="root").children.get()

# Create temporary local directory for storage of the files
local_dir = "./" + str(time.time())
i = 0;
コード例 #45
0
ファイル: auth.py プロジェクト: fjjupc/OneDrive
#!/usr/bin/env python
# Author:   Carl Fan
# Mail:     [email protected]
# Describe: Get authorized by OneDrive

from get_client_info import client_id, client_secret

import onedrivesdk
from onedrivesdk.helpers import GetAuthCodeServer

# See Should be set in your application settings in https://account.live.com/developers/applications/index
redirect_uri = "http://localhost:8080/"

client = onedrivesdk.get_default_client(
	client_id,
    ['wl.signin', #Allows your application to take advantage of single sign-on capabilities.
     'wl.offline_access', #Allows your application to receive a refresh token so it can work offline even when the user isn't active.
     'onedrive.readwrite' # Grants read and write permission to all of a user's OneDrive files, including files shared with the user. To create sharing links, this scope is required.
    ])

auth_url = client.auth_provider.get_auth_url(redirect_uri)

#this will block until we have the code
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

client.auth_provider.authenticate(code, redirect_uri, client_secret)