Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
__author__ = 'RaspiRepo'
import onedrivesdk
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
#Onedrive Access
redirect_uri = "https://login.live.com/oauth20_desktop.srf"
client_secret = "client_secret"
client_id_str = "client_id"
user_name = 'username'
password = 'your password'
client = onedrivesdk.get_default_client(client_id=client_id_str,
scopes=['wl.signin',
'wl.offline_access',
'onedrive.readwrite'])
auth_url = client.auth_provider.get_auth_url(redirect_uri)
driver = webdriver.PhantomJS() # 'phantomjs')
driver.set_window_size(320,240)
driver.maximize_window()
# chrome_driver = webdriver.Chrome('chromedriver')
# chrome_driver.set_window_size(2, 2)
driver.get(auth_url)
driver.implicitly_wait(8)
driver.get(auth_url)
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')
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
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))