Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Secrets, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
secrets: HCkSecrets;
json: HCkJsonObject;
json2: HCkJsonObject;

begin
success := False;

// 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

secrets := CkSecrets_Create();

json := CkJsonObject_Create();

CkJsonObject_UpdateString(json,'appName','sharepoint');
CkJsonObject_UpdateString(json,'service','oauth2');
CkJsonObject_UpdateString(json,'username','client_id');

// These are not actual/real values..
success := CkSecrets_UpdateSecretStr(secrets,json,'4afc67c5-6d3f-4ed0-91c7-5d239c78bff7');
if (success = False) then
  begin
    Memo1.Lines.Add(CkSecrets__lastErrorText(secrets));
    Exit;
  end;

CkJsonObject_UpdateString(json,'username','client_secret');
success := CkSecrets_UpdateSecretStr(secrets,json,'Rlh8Q~xaP10Dw-goWQDLXrRJfYAFVW1hHauvfhO6');
if (success = False) then
  begin
    Memo1.Lines.Add(CkSecrets__lastErrorText(secrets));
    Exit;
  end;

CkJsonObject_UpdateString(json,'username','token_endpoint');
success := CkSecrets_UpdateSecretStr(secrets,json,'https://login.microsoftonline.com/5f410b89-177f-40b3-9d66-ac519c728025/oauth2/v2.0/token');
if (success = False) then
  begin
    Memo1.Lines.Add(CkSecrets__lastErrorText(secrets));
    Exit;
  end;

// -----------------------------------------------------------------------------------------------------------
// The above secrets would be accessed like this:
json2 := CkJsonObject_Create();

CkJsonObject_putEnableSecrets(json2,True);

// Chilkat sees the secret specification string (beginning with "!!") and resolves from the local manager.
CkJsonObject_UpdateString(json2,'x','!!sharepoint|oauth2|client_id');
Memo1.Lines.Add('x = ' + CkJsonObject__stringOf(json2,'x'));

CkJsonObject_UpdateString(json2,'y','!!sharepoint|oauth2|client_secret');
Memo1.Lines.Add('y = ' + CkJsonObject__stringOf(json2,'y'));

CkJsonObject_UpdateString(json2,'z','!!sharepoint|oauth2|token_endpoint');
Memo1.Lines.Add('z = ' + CkJsonObject__stringOf(json2,'z'));

// 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

CkSecrets_Dispose(secrets);
CkJsonObject_Dispose(json);
CkJsonObject_Dispose(json2);

end;