External user in sharepoint site unable to get auth token
Good day,
I have the following error:
ValueError: Acquire token failed: An error occurred while retrieving auth cookies from https://<externalCompany>.sharepoint.com/_forms/default.aspx?wa=wsignin1.0.
I am from myCompany and were given full access to https://<externalCompany>.sharepoint.com/sites/ABC/SitePages/Home.aspx.
So my code is shared below.
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
username = "[email protected]"
password = "securepassword"
site_url = "https://<externalCompany>.sharepoint.com/sites/ABC"
ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
request = RequestOptions("{0}/_api/web/lists/GetByTitle('Documents')/items?$select=FileLeafRef,FileRef".format(site_url))
response = ctx.execute_request_direct(request)
json = json.loads(response.content)
files = json['d']['results']
for file in files:
source = "https://" + site_url + file["FileRef"]
# Check if item is file or folder
check_request = RequestOptions("{}/_api/web/GetFolderByServerRelativeUrl('{}')"
.format(site_url, file["FileRef"]))
folder = ctx.execute_request_direct(check_request).status_code == 200
print(folder)
print(source)
I was wondering is there API settings where this feature has been disabled? Is there a way for me to check? And can I give instructions to externalCompany to enable this feature? I cant find any documentation about it.
full error is below
An error occurred while retrieving auth cookies from https://externalCompany.sharepoint.com/_forms/default.aspx?wa=wsignin1.0
Traceback (most recent call last):
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\test_Office365-REST-Python-Client.py", line 17, in <module>
response = ctx.execute_request_direct(request)
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\office365\runtime\client_runtime_context.py", line 136, in execute_request_direct
return self.pending_request().execute_request_direct(request)
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\office365\runtime\odata\odata_request.py", line 34, in execute_request_direct
return super(ODataRequest, self).execute_request_direct(request)
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\office365\runtime\client_request.py", line 86, in execute_request_direct
self.context.authenticate_request(request_options)
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\office365\runtime\client_runtime_context.py", line 66, in authenticate_request
self._auth_context.authenticate_request(request)
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\office365\runtime\auth\authentication_context.py", line 70, in authenticate_request
self.acquire_token_func()
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\office365\sharepoint\client_context.py", line 124, in _acquire_token
return self.authentication_context.acquire_token_for_user(credentials.userName,
File "C:\Users\mark\OneDrive\projects\lambda\sharepoint\office365\runtime\auth\authentication_context.py", line 38, in acquire_token_for_user
raise ValueError('Acquire token failed: {0}'.format(self.provider.error))
ValueError: Acquire token failed: An error occurred while retrieving auth cookies from https://externalCompany.sharepoint.com/_forms/default.aspx?wa=wsignin1.0
Any update on this issue? We have been seeing the same error for a couple of weeks that has broken our application. I would help but I'm not sure how. I noticed that the post request to /_forms/default.aspx?wa=wsignin1.0 is no longer returning and 302 (its now 200) and it doesn't return any cookies either, and that causes it to break. Any known fixes, or at least what is causing it?
I am getting this error too. It is not a bug, it is probably a security configuration from the SharePoint tenant hosting the site.