Example #1
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')
Example #2
0
    def authenticate(self):
        if os.path.exists(session_file_path):
            self.client.auth_provider.load_session(path=session_file_path)
            self.client.auth_provider.refresh_token()
        else:
            auth_url = self.client.auth_provider.get_auth_url(redirect_uri)
            if os.name == 'posix' and (('ANDROID_DATA' in os.environ
                                        )  # hacky way to know we are on termux
                                       or
                                       ('Microsoft' in os.uname()[3])):  # WSL
                # Ask for the code
                print(
                    'Paste this URL into your browser, approve the app\'s access.'
                )
                print(
                    'Copy everything in the address bar after "code=", and paste it below.'
                )
                print(auth_url)
                code = input('Paste code here: ')

            else:  # system has a browser:
                # this will block until we have the auth code :
                code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)

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

        self.client.auth_provider.save_session(path=session_file_path)
Example #3
0
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()
Example #4
0
    def bauthenticator(self):
        from onedrivesdk.helpers.resource_discovery import ResourceDiscoveryRequest

        discovery_uri = 'https://api.office.com/discovery/'
        auth_server_url = 'https://login.microsoftonline.com/common/oauth2/authorize'
        auth_token_url = 'https://login.microsoftonline.com/common/oauth2/token'

        http = onedrivesdk.HttpProvider()
        auth = onedrivesdk.AuthProvider(http,
                                        self.client_id,
                                        auth_server_url=auth_server_url,
                                        auth_token_url=auth_token_url)
        auth_url = auth.get_auth_url(redirect_uri)
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
        auth.authenticate(code,
                          redirect_uri,
                          self.client_secret,
                          resource=discovery_uri)
        # If you have access to more than one service, you'll need to decide
        # which ServiceInfo to use instead of just using the first one, as below.
        service_info = ResourceDiscoveryRequest().get_service_info(
            auth.access_token)[0]
        auth.redeem_refresh_token(service_info.service_resource_id)
        client = onedrivesdk.OneDriveClient(
            service_info.service_resource_id + '/_api/v2.0/', auth, http)

        return client
Example #5
0
    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)
Example #6
0
	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;
Example #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
Example #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
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
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
Example #11
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
Example #12
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)
Example #13
0
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
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
Example #15
0
 def authenticate(self):
     """ Authenticate to onedrive and return is success or not """
     log('Onedrive: Authenticate')
     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)
     # Finally, authenticate!
     try:
         self.client.auth_provider.authenticate(code, self.redirect_uri,
                                                self.client_secret)
     except onedrivesdk.error.ErrorCode as error:
         log(error)
         return False
     return True
Example #16
0
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.")
Example #17
0
    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
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)
    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()
Example #20
0
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)
Example #21
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
Example #22
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
Example #23
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
Example #24
0
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)
Example #25
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')
Example #26
0
def Authentication():
    http = sdk.HttpProvider()  # sdk.HttpProvider()
    auth = sdk.AuthProvider(http,
                            client_id,
                            auth_server_url=auth_server_url,
                            auth_token_url=auth_token_url)
    auth_url = auth.get_auth_url(redirect_uri)
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    auth.authenticate(code,
                      redirect_uri,
                      client_secret,
                      resource=discovery_uri)
    # If you have access to more than one service, you'll need to decide
    # which ServiceInfo to use instead of just using the first one, as below.
    service_info = ResourceDiscoveryRequest().get_service_info(
        auth.access_token)[0]
    auth.redeem_refresh_token(service_info.service_resource_id)
    client = sdk.OneDriveClient(
        service_info.service_resource_id + '/_api/v2.0/', auth, http)
Example #27
0
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
Example #28
0
    def authenticate(self, cache, client_secret):
        assert cache

        auth_url = self.auth.get_auth_url(redirect_uri)
        code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
        self.auth.authenticate(code,
                               redirect_uri,
                               client_secret,
                               resource=discovery_uri)

        # If you have access to more than one service, you'll need to decide
        # which ServiceInfo to use instead of just using the first one, as below.
        service_info = ResourceDiscoveryRequest().get_service_info(
            self.auth.access_token)[0]
        self.auth.redeem_refresh_token(service_info.service_resource_id)

        print(service_info.service_resource_id)

        # Save the session for later
        self.auth.save_session(path=cache)
    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")
Example #30
0
    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
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")
Example #32
0
    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"
Example #33
0
    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
Example #34
0
def get_onedrive_client(client_id, client_secret):
    """
    Initializes onedrive client
    :param client_id: str
        application id
    :param client_secret: str
        client secret
    :return:
        onedrive api client
    """
    redirect_uri = 'http://localhost:8080/'
    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
    logger.info('Obtaining the code')
    code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
    logger.info('authenticating')
    client.auth_provider.authenticate(code, redirect_uri, client_secret)
    return client
Example #35
0
 def login_business(self, redirect_uri, client_id, client_secret,
                    discovery_uri, auth_server_url, auth_token_url):
     http = onedrivesdk.HttpProvider()
     auth = onedrivesdk.AuthProvider(http,
                                     client_id,
                                     auth_server_url=auth_server_url,
                                     auth_token_url=auth_token_url)
     auth_url = auth.get_auth_url(redirect_uri)
     code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri)
     auth.authenticate(code,
                       redirect_uri,
                       client_secret,
                       resource=discovery_uri)
     services = ResourceDiscoveryRequest().get_service_info(
         auth.access_token)
     for service in services:
         if service.service_id == 'O365_SHAREPOINT':
             auth.redeem_refresh_token(service.service_resource_id)
             client = onedrivesdk.OneDriveClient(
                 service.service_resource_id + '/_api/v2.0/', auth, http)
             self.client = client
             return True
     return False
Example #36
0
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
Example #37
0
		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

for item in items:

		espOne+=int(item.size)
#--------------------------------------------------------------------

class Application(Frame):