Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PureBasic Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PureBasic) 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 v9.5.0.73.

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 support@chilkatsoft.com. 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.

Chilkat PureBasic Module Download

Chilkat PureBasic Module

IncludeFile "CkXml.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkSecureString.pb"

Procedure ChilkatExample()

    ; This requires the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    success.i
    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Change these things...
    ; Make sure to use "https" and end in a "/".
    siteUrl.s = "https://mydomain.sharepoint.com/"
    ; The username is an email address.
    username.s = "username@mydomain.com"

    ; The jsonExtra is for future use, if extra information is required for particular integrations.
    jsonExtra.i = CkJsonObject::ckCreate()
    If jsonExtra.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ssPassword.i = CkSecureString::ckCreate()
    If ssPassword.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkSecureString::ckAppend(ssPassword,"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).
    CkHttp::setCkSaveCookies(http, 1)
    CkHttp::setCkSendCookies(http, 1)
    CkHttp::setCkCookieDir(http, "memory")

    ; The SharePointOnlineAuth method is introduced in Chilkat v9.5.0.73
    success = CkHttp::ckSharePointOnlineAuth(http,siteUrl,username,ssPassword,jsonExtra)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonExtra)
        CkSecureString::ckDispose(ssPassword)
        ProcedureReturn
    EndIf

    Debug "Success! We have the SPOIDCRL cookie..."

    ; -----------------------------------------------------------------------------------------------------------
    ; IMPORTANT:
    ; The purpose of the SharePointOnlineAuth method is to establish the SPOIDCRL cookie that will automatically be
    ; included in subsequent requests using the *** same HTTP object instance. ***
    ; If later you create a new HTTP object instance, then you'll need to re-establish the SPOIDCRL cookie before sending 
    ; a Sharepoint HTTP request.
    ; -----------------------------------------------------------------------------------------------------------

    ; SharePoint authenticated requests may now be sent because the authentication cookie is automatically included.
    ; For example:
    sbResponseXml.i = CkStringBuilder::ckCreate()
    If sbResponseXml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; If your Sharepoint site is within a site collection, then use "https://mydomain.sharepoint.com/sites/teamA/_api/web/GetFolderByServerRelativeUrl('/sites/teamA/Documents')/Files" where "teamA" is the name of the site.
    success = CkHttp::ckQuickGetSb(http,"https://mydomain.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('/Documents')/Files",sbResponseXml)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(jsonExtra)
        CkSecureString::ckDispose(ssPassword)
        CkStringBuilder::ckDispose(sbResponseXml)
        ProcedureReturn
    EndIf

    Debug "Response status code = " + Str(CkHttp::ckLastStatus(http))

    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkXml::ckLoadSb(xml,sbResponseXml,1)
    Debug CkXml::ckGetXml(xml)


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(jsonExtra)
    CkSecureString::ckDispose(ssPassword)
    CkStringBuilder::ckDispose(sbResponseXml)
    CkXml::ckDispose(xml)


    ProcedureReturn
EndProcedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.