Ssl certificate 无法使用所有Python插件的用户名和密码验证SharePoint API
我的用例是从公司的sharepoint(在线)站点获取一些文件。我已被授予通过SharePoint API连接的用户名密码的读取权限。对于呼叫,我必须通过代理和公司SSL验证 我尝试过使用许多API,如、、HTTPBasicAuth,但所有这些API都给了我[SSL:CERTIFICATE\u VERIFY\u FAILED]错误 我不确定是否可以向这些API传递证书 有没有其他插件可以尝试用于我的场景?为此,我对向API发送请求的常用函数进行了猴子补丁。以下是一些此类功能的示例:Ssl certificate 无法使用所有Python插件的用户名和密码验证SharePoint API,ssl-certificate,python-3.7,sharepoint-online,sharepoint-api,Ssl Certificate,Python 3.7,Sharepoint Online,Sharepoint Api,我的用例是从公司的sharepoint(在线)站点获取一些文件。我已被授予通过SharePoint API连接的用户名密码的读取权限。对于呼叫,我必须通过代理和公司SSL验证 我尝试过使用许多API,如、、HTTPBasicAuth,但所有这些API都给了我[SSL:CERTIFICATE\u VERIFY\u FAILED]错误 我不确定是否可以向这些API传递证书 有没有其他插件可以尝试用于我的场景?为此,我对向API发送请求的常用函数进行了猴子补丁。以下是一些此类功能的示例: class
class SharePointApi:
"""SharePoint aceess api."""
def __init__(self):
self.base_url = configReader.get('SHAREPOINT', 'URL')
self.ctx_auth = AuthenticationContext(self.base_url)
self.ctx_auth.provider = SamlTokenProvider(self.base_url, username, password)
self.ctx_auth.provider.acquire_service_token = self._patched_acquire_service_token
self.ctx_auth.provider.acquire_authentication_cookie = self._patched_acquire_authentication_cookie
self.ctx_auth.provider.get_realm_from_target_url = self._patched_get_realm_from_target_url
self.ctx_auth.provider.get_app_only_access_token = self._patched_get_app_only_access_token
def _patched_acquire_authentication_cookie(self, options):
"""Retrieve SPO auth cookie"""
url = options['endpoint']
session = requests.session()
session.post(url, data=self.ctx_auth.provider.token, headers={'Content-Type': 'application/x-www-form-urlencoded'}
, verify=False
)
logger.debug_secrets("session.cookies: %s", session.cookies)
cookies = requests.utils.dict_from_cookiejar(session.cookies)
logger.debug_secrets("cookies: %s", cookies)
if 'FedAuth' in cookies and 'rtFa' in cookies:
self.ctx_auth.provider.FedAuth = cookies['FedAuth']
self.ctx_auth.provider.rtFa = cookies['rtFa']
return True
self.ctx_auth.provider.error = "An error occurred while retrieving auth cookies"
logger.error(self.ctx_auth.provider.error)
return False
def _patched_get_realm_from_target_url(self):
response = requests.head(url=self.ctx_auth.provider.url, headers={'Authorization': 'Bearer'}, verify=False, proxies=proxies)
return self.ctx_auth.provider.process_realm_response(response)
def _patched_get_app_only_access_token(self, target_host, target_realm):
resource = self.ctx_auth.provider.get_formatted_principal(self.ctx_auth.provider.SharePointPrincipal, target_host, target_realm)
client_id = self.ctx_auth.provider.get_formatted_principal(self.ctx_auth.provider.client_id, None, target_realm)
sts_url = self.ctx_auth.provider.get_security_token_service_url(target_realm)
oauth2_request = self.ctx_auth.provider.create_access_token_request(client_id, self.ctx_auth.provider.client_secret, resource)
response = requests.post(url=sts_url, headers={'Content-Type': 'application/x-www-form-urlencoded'}, data=oauth2_request, verify=False, proxies=proxies)
return response.json()