Sample code for 30+ languages & platforms
DataFlex

curl Update Local Manager Secrets

See more CURL Examples

Demonstrates how to initially write secrets to the local manager that will later be used in curl commands. On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSecrets
    Variant vJson
    Handle hoJson
    Variant vJson
2    Handle hoJson2
    String sTemp1

    Move False To iSuccess

    // This example will store 3 secrets in the local manager.

    // On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.
    // These secrets will be used at a later point in time in curl commands,
    // as shown in this example:  Using Local Manager Secrets with curl

    // Also see: Chilkat v11.5.0 — Secrets Integration
    // and also: Chilkat Secrets API

    Get Create (RefClass(cComChilkatSecrets)) To hoSecrets
    If (Not(IsComObjectCreated(hoSecrets))) Begin
        Send CreateComObject of hoSecrets
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End

    Get ComUpdateString Of hoJson "appName" "sharepoint" To iSuccess
    Get ComUpdateString Of hoJson "service" "oauth2" To iSuccess
    Get ComUpdateString Of hoJson "username" "client_id" To iSuccess

    // These are not actual/real values..
    Get pvComObject of hoJson to vJson
    Get ComUpdateSecretStr Of hoSecrets vJson "4afc67c5-6d3f-4ed0-91c7-5d239c78bff7" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSecrets To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComUpdateString Of hoJson "username" "client_secret" To iSuccess
    Get pvComObject of hoJson to vJson
    Get ComUpdateSecretStr Of hoSecrets vJson "Rlh8Q~xaP10Dw-goWQDLXrRJfYAFVW1hHauvfhO6" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSecrets To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComUpdateString Of hoJson "username" "token_endpoint" To iSuccess
    Get pvComObject of hoJson to vJson
    Get ComUpdateSecretStr Of hoSecrets vJson "https://login.microsoftonline.com/5f410b89-177f-40b3-9d66-ac519c728025/oauth2/v2.0/token" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoSecrets To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // -----------------------------------------------------------------------------------------------------------
    // The above secrets would be accessed like this:
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson2
    If (Not(IsComObjectCreated(hoJson2))) Begin
        Send CreateComObject of hoJson2
    End

    Set ComEnableSecrets Of hoJson2 To True

    // Chilkat sees the secret specification string (beginning with "!!") and resolves from the local manager.
    Get ComUpdateString Of hoJson2 "x" "!!sharepoint|oauth2|client_id" To iSuccess
    Get ComStringOf Of hoJson2 "x" To sTemp1
    Showln "x = " sTemp1

    Get ComUpdateString Of hoJson2 "y" "!!sharepoint|oauth2|client_secret" To iSuccess
    Get ComStringOf Of hoJson2 "y" To sTemp1
    Showln "y = " sTemp1

    Get ComUpdateString Of hoJson2 "z" "!!sharepoint|oauth2|token_endpoint" To iSuccess
    Get ComStringOf Of hoJson2 "z" To sTemp1
    Showln "z = " sTemp1

    // You can see the values retrieved from the local manager:

    // x = 4afc67c5-6d3f-4ed0-91c7-5d239c78bff7
    // y = Rlh8Q~xaP10Dw-goWQDLXrRJfYAFVW1hHauvfhO6
    // z = https://login.microsoftonline.com/5f410b89-177f-40b3-9d66-ac519c728025/oauth2/v2.0/token


End_Procedure