1

I'm trying to authenticate to SharePoint Online. Using sharepy v 2.0, pyCharm community edition, and python 3.9.

When I run:

'sharepy.connect('siteurl')'

From within PyCharm, Sharepy will freeze after I input my username in the run dialog box.

If I add the 'username' parameter and run it. Nothing happens. I'm never prompted for a password

If I use the console and enter in sharepy.connect('siteurl') then username and password (same goes for passing those parameters) I will get an error:

Traceback (most recent call last):
  File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 75, in _get_token
    token = root.find('.//wsse:BinarySecurityToken', ns).text
AttributeError: 'NoneType' object has no attribute 'text'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\session.py", line 15, in connect
    return SharePointSession(site, auth=autoauth)
  File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\session.py", line 61, in __init__
    self.auth.login(self.site)
  File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 27, in login
    self._get_token()
  File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 77, in _get_token
    raise errors.AuthError('Token request failed. Invalid server response')
sharepy.errors.AuthError: Token request failed. Invalid server response

It should be noted I'm getting O365 from godaddy and the login page is federated? I think is the correct term.

According to the new release of Sharepy, this shouldn't matter.

Has anyone else had this freezing problem happen for them? How would I authenticate with sharepoint using sharepy given my current situation?

TxTechnician
  • 318
  • 1
  • 11
  • Same issue here: `s = sharepy.connect(SPUrl, username, password)` even though I pass username and password. – Bence Kaulics Jun 30 '22 at 18:24
  • @BenceKaulics I found the source of my problem and also the source of another problem following the solution. I'll answer my own question soon. – TxTechnician Jul 06 '22 at 21:02
  • Thanks for your answer, it helped. Now that I have read it, I have realized that in my case the 2FA is the problem which also happens on a redirect site. – Bence Kaulics Jul 07 '22 at 15:03

1 Answers1

1

The source of this problem ended up being GoDaddy. As we were federated using GoDaddy as the O365 provider. There was no way to authenticate correctly using sharepy.

The ultimate solution was to defederate away from GoDaddy (pretty easy to do thanks to this guy: Defederation Guide)

The reason we were unable to authenticate was because our provider redirects the login to their own login site. And unfortunately the sharepy builtin method of "auth" wouldn't work with GoDaddy.

I tested this theory before migrating away from GoDaddy. By using a fresh tenant. I also found that when you enable MFA the password/username method of authentication doesn't work.

NOTE: When new tenants are created they utilize a blanket security protocol which forces MFA. Even though MFA is shown as disabled in the Azure AD > Users section. To turn this off you must disable "Security Defaults": portal.azure.com > Azure Active Directory > Properties > "Manage security defaults" (at the bottom of the screen, its a small hyperlink).

A note on MFA and authentication with sharepy. There are methods to leave MFA enabled which work with other sharepoint/python things. I haven't tested them using sharepy yet, but will be turning on MFA and using one of the following methods:

  1. App Password
  2. Sharepoint API client secret
  3. Azure App Registration (Azure App Reg)
TxTechnician
  • 318
  • 1
  • 11