Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaJavaScriptNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples
Web API Categories

AI
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
Box
CAdES
CSR
CSV
Cert Store
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)
JavaScript
MHT / HTML Email
MIME
Markdown
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
Regular Expressions
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) curl with use of Local Manager Secrets for Credentials

See more CURL Examples
This example demonstrates how to retrieve secrets from the local credential manager instead of embedding them directly in your source code.

On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.

Note: This example requires Chilkat v11.5.0 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSb
    Variant vJsonOAuth2
    Handle hoJsonOAuth2
    Handle hoHttpCurl
    Variant vResponseJson
    Handle hoResponseJson
    Integer iStatusCode
    String sTemp1

    Move False To iSuccess

    // This example will run the following curl command

    // curl -X GET "https://graph.microsoft.com/v1.0/sites/{{sharepoint_hostname}}:/sites/{{site_name}}" \
    //   -H "Authorization: Bearer ACCESS_TOKEN" \
    //   -H "Accept: application/json"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End
    Get ComAppendLn Of hoSb 'curl -X GET "https://graph.microsoft.com/v1.0/sites/{{sharepoint_hostname}}:/sites/{{site_name}}" \' To iSuccess
    Get ComAppendLn Of hoSb '  -H "Authorization: Bearer ACCESS_TOKEN" \' To iSuccess
    Get ComAppendLn Of hoSb '  -H "Accept: application/json"' To iSuccess

    // Build the JSON that provides information for getting the OAuth2 access token using the OAuth2 client credentials flow.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOAuth2
    If (Not(IsComObjectCreated(hoJsonOAuth2))) Begin
        Send CreateComObject of hoJsonOAuth2
    End

    // The notation "!!sharepoint|oauth2|client_id" is a secrets specification string 
    // that can have up to 4 components: !!appName|service|domain|username
    // where appName and domain are optional.
    // See Chilkat v11.5.0 — Secrets Integration
    // Also see: Chilkat Secrets API

    // The following example shows how to store (or update) the secrets used in this example
    // Storing Secrets in the Local Manager

    // We must enable secrets integration for Chilkat to auto-resolve when the string begins with "!!".
    Set ComEnableSecrets Of hoJsonOAuth2 To True
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.client_id" "!!sharepoint|oauth2|client_id" To iSuccess
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.client_secret" "!!sharepoint|oauth2|client_secret" To iSuccess
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.scope" "https://graph.microsoft.com/.default" To iSuccess
    Get ComUpdateString Of hoJsonOAuth2 "oauth2.token_endpoint" "!!sharepoint|oauth2|token_endpoint" To iSuccess

    Get Create (RefClass(cComChilkatHttpCurl)) To hoHttpCurl
    If (Not(IsComObjectCreated(hoHttpCurl))) Begin
        Send CreateComObject of hoHttpCurl
    End

    // Provide the information for getting the OAuth2 access token from the token endpoint
    // Note: The Authorization header specified in the curl command will be ignored and replaced using the OAuth2 access token obtained at runtime from the token endpoint.
    Get pvComObject of hoJsonOAuth2 to vJsonOAuth2
    Get ComSetAuth Of hoHttpCurl vJsonOAuth2 To iSuccess

    // The placeholders {{sharepoint_hostname}} and {{site_name}} represent variables that must be defined before execution.
    // When DoYourThing runs the curl command, it automatically substitutes these placeholders with their corresponding values.
    // Below are the values assigned to these variables:
    Send ComSetVar To hoHttpCurl "sharepoint_hostname" "example.sharepoint.com"
    Send ComSetVar To hoHttpCurl "site_name" "test"

    // Run the curl command.
    Get ComGetAsString Of hoSb To sTemp1
    Get ComDoYourThing Of hoHttpCurl sTemp1 To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttpCurl To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoResponseJson
    If (Not(IsComObjectCreated(hoResponseJson))) Begin
        Send CreateComObject of hoResponseJson
    End
    Set ComEmitCompact Of hoResponseJson To False

    Get pvComObject of hoResponseJson to vResponseJson
    Get ComGetResponseJson Of hoHttpCurl vResponseJson To iSuccess

    Get ComStatusCode Of hoHttpCurl To iStatusCode
    Showln "response status code: " iStatusCode

    Get ComEmit Of hoResponseJson To sTemp1
    Showln sTemp1


End_Procedure

 

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