Sharepoint Binary Security Token

See original GitHub issue

Hello, My goal is given a sharepoint link to a site folder, to list the files, and to copy any new files automatically to AWS S3. When I run the simple startup script, I am getting the error:

Cannot get binary security token for from https://login.microsoftonline.com/extSTS.srf
Traceback (most recent call last):
  File "/Users/riple2/PycharmProjects/os365/microsoft/test5.py", line 10, in <module>
    response = ctx.execute_request_direct(request)
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/client_runtime_context.py", line 134, in execute_request_direct
    return self.pending_request().execute_request_direct(request)
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/odata/odata_request.py", line 34, in execute_request_direct
    return super(ODataRequest, self).execute_request_direct(request)
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/client_request.py", line 86, in execute_request_direct
    self.context.authenticate_request(request_options)
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/sharepoint/client_context.py", line 153, in authenticate_request
    self._auth_context.authenticate_request(request)
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/auth/authentication_context.py", line 84, in authenticate_request
    self._provider.authenticate_request(request)
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/auth/providers/saml_token_provider.py", line 73, in authenticate_request
    self.ensure_authentication_cookie()
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/auth/providers/saml_token_provider.py", line 80, in ensure_authentication_cookie
    self._cached_auth_cookies = self.get_authentication_cookie()
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/auth/providers/saml_token_provider.py", line 95, in get_authentication_cookie
    token = self._acquire_service_token()
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/auth/providers/saml_token_provider.py", line 172, in _acquire_service_token
    token = self._process_service_token_response(response)
  File "/Users/riple2/Library/Python/3.8/lib/python/site-packages/office365/runtime/auth/providers/saml_token_provider.py", line 207, in _process_service_token_response
    raise ValueError(self.error)
ValueError: Cannot get binary security token for from https://login.microsoftonline.com/extSTS.srf

The simple script I am running is:

import json
from office365.runtime.auth.user_credential import UserCredential
from office365.runtime.http.request_options import RequestOptions
from office365.sharepoint.client_context import ClientContext
site_url="https://levi.sharepoint.com/sites/gdo/"
with open('secrets.json') as f:
  secrets = json.load(f)
ctx = ClientContext(site_url).with_credentials(UserCredential(secrets['user'], secrets['password']))
request = RequestOptions("{0}/_api/web/".format(site_url))
response = ctx.execute_request_direct(request)
json = json.loads(response.content)
web_title = json['d']['Title']
print("Web title: {0}".format(web_title))

I am using my Levi organization’s username and password to the same site https://levi.sharepoint.com/sites/gdo/ . I can easily access this site in my browser, but the python package is having this authentication error.

What is needed besides username and password to get programatic access to sharepoint folders?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

14reactions
rajvijay68commented, Aug 30, 2021

I too got this error. I was using just my “username”. Using “username@xyz.com” worked for me.

1reaction
ishaan-k03commented, May 23, 2022

Only issue could be with your username value it should be proper email ‘xyz@email.com’ check this properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load files from SharePoint in Python - Stack Overflow
Cannot get binary security token for from ... site_url="https://{tenant}.sharepoint.com/sites/{yoursite}" if ...
Read more >
SharePoint Online Active Authentication
The “STSAuthURL” node in the XML response contains the value. Step 2: Authenticating to the STS and Retrieving the BinarySecurityToken
Read more >
Sharepoint Online: Encrypted security token - MSDN - Microsoft
For step 1 (getting the security token), I sent a POST request to https://login.microsoftonline.com/extSTS.srf ... <wsse:BinarySecurityToken ...
Read more >
How do I get access token for SharePoint Online REST API
scope=https://<tenant>.sharepoint.com/Sites.FullControl.All. 144775-image.png. 3.Take the access token and call the SPO API. Make sure that you ...
Read more >
Cant retrieve BinarySecurityToken from SAML Response of ...
With Microsoft operated Office365 our REST client is able to completed authentication process as it could read the BinarySecurityToken.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found