Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/sharepy/auth/adfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def __init__(self, *args, **kwargs):
def login(self, site):
"""Perform authentication steps"""
self.site = site
self._get_token()
self._get_cookie()
self._get_digest()
got_token = self._get_token()
got_cookie = self._get_cookie()
refreshed = self._get_digest()
return all([got_token, got_cookie, refreshed])

def refresh(self):
return self._get_digest()
Expand Down Expand Up @@ -118,6 +119,8 @@ def _get_digest(self):
# Calculate digest expiry time
self.expire = datetime.now() + timedelta(seconds=timeout)

return True

def _buildcookie(self, cookies):
"""Create session cookie from response cookie dictionary"""
return 'SPOIDCRL=' + cookies['SPOIDCRL']
Expand Down
13 changes: 9 additions & 4 deletions src/sharepy/auth/spol.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def __init__(self, *args, **kwargs):
def login(self, site):
"""Perform authentication steps"""
self.site = site
self._get_token()
self._get_cookie()
self._get_digest()
got_token = self._get_token()
got_cookie = self._get_cookie()
refreshed = self._get_digest()
return all([got_token, got_cookie, refreshed])

def refresh(self):
return self._get_digest()
Expand All @@ -50,6 +51,7 @@ def _get_token(self):
raise errors.AuthError.fromxml(root)

self.token = token.text
return True

def _get_cookie(self):
"""Request access cookie from sharepoint site"""
Expand All @@ -64,6 +66,7 @@ def _get_cookie(self):

if response.status_code == requests.codes.ok:
self.cookie = cookie
return True
else:
raise errors.AuthError('Authentication failed')

Expand All @@ -84,7 +87,9 @@ def _get_digest(self):
# Calculate digest expiry time
self.expire = datetime.now() + timedelta(seconds=timeout)

return True
return True

return False

def _buildcookie(self, cookies):
"""Create session cookie from response cookie dictionary"""
Expand Down
5 changes: 3 additions & 2 deletions src/sharepy/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from . import __version__
from . import auth
from . import errors
from sharepy.auth.base import BaseAuth


def connect(site, username=None, password=None):
Expand All @@ -25,7 +26,7 @@ def load(filename='sp-session.pkl'):
raise errors.SessionError('The session is not compatible with the current SharePy version')

# Try to authenticate the saved session
if session.auth.refresh() or session.auth.login():
if session.auth.refresh() or session.auth.login(session.site):
# Re-save session to prevent it going stale
try:
session.save(filename)
Expand All @@ -47,7 +48,7 @@ class SharePointSession(requests.Session):
<Response [200]>
"""

def __init__(self, site=None, auth=None):
def __init__(self, site=None, auth: BaseAuth = None):
super().__init__()
self.version = __version__

Expand Down