Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(Python) SharePoint Online Authentication
Demonstrates how to authenticate with SharePoint Online. The end result of authentication is to establish an HTTP cookie, named "SPOIDCRL", that contains a binary security token to be sent in subsequent SharePoint HTTPS requests.
The SPOIDCRL cookie can be persisted to a file and re-used in subsequent application runs.
Important: This example uses a method, SharePointOnlineAuth, that is introduced in Chilkat v126.96.36.199.
Also Important: Chilkat realizes there may be cases where your situation is such that it does not work, and something additional is required to make it work. If the example does not work out-of-the-box, please send email to firstname.lastname@example.org. The information logged to the LastErrorText property has been carefully crafted to help solve problems quickly. Also, the JSON argument to the SharePointOnlineAuth method provides a means to include additional information, whatever it may be, to handle future unknown situations.
import sys import chilkat # This requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. http = chilkat.CkHttp() # Change these things... # Make sure to use "https" and end in a "/". siteUrl = "https://mydomain.sharepoint.com/" # The username is an email address. username = "email@example.com" # The jsonExtra is for future use, if extra information is required for particular integrations. jsonExtra = chilkat.CkJsonObject() ssPassword = chilkat.CkSecureString() ssPassword.Append("mypassword") # Set properties to save/send cookies, and specify a cookie directory. # If the CookieDir = "memory", then the SPOIDCRL cookie is persisted in memory for this HTTP object instance only. # To persist the SharePoint authentication cookie for other HTTP objects, and for future application runs, # set the CookieDir equal to a directory path (not a specific file path, but a directory path where cookie files # are to be created). http.put_SaveCookies(True) http.put_SendCookies(True) http.put_CookieDir("memory") # The SharePointOnlineAuth method is introduced in Chilkat v188.8.131.52 success = http.SharePointOnlineAuth(siteUrl,username,ssPassword,jsonExtra) if (success == False): print(http.lastErrorText()) sys.exit() print("Success! We have the SPOIDCRL cookie...") # SharePoint authenticated requests may now be sent because the authentication cookie is automatically included. # For example: sbResponseXml = chilkat.CkStringBuilder() success = http.QuickGetSb("https://mydomain.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Documents')/Files",sbResponseXml) if (success == False): print(http.lastErrorText()) sys.exit() print("Response status code = " + str(http.get_LastStatus())) xml = chilkat.CkXml() xml.LoadSb(sbResponseXml,True) print(xml.getXml())
© 2000-2020 Chilkat Software, Inc. All Rights Reserved.