Lazarus Pascal
Lazarus Pascal
Example: Http.SetOAuthRsaKey method
Demonstrates theSetOAuthRsaKey method.
Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Pfx,
Chilkat.PrivateKey,
Chilkat.HttpResponse,
Chilkat.Http;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pfx: TPfx;
privKey: TPrivateKey;
http: THttp;
resp: THttpResponse;
begin
success := False;
pfx := TPfx.Create;
success := pfx.LoadPfxFile('qa_data/pfx/MCD_Sandbox_chilkat_iccp_API_Keys/chilkat_iccp-sandbox.p12','keystorepassword');
if (success = False) then
begin
WriteLn(pfx.LastErrorText);
Exit;
end;
privKey := TPrivateKey.Create;
success := pfx.PrivateKeyAt(0,privKey);
if (success = False) then
begin
WriteLn(pfx.LastErrorText);
Exit;
end;
http := THttp.Create;
// Use OAuth1.0a authentication.
http.OAuth1 := True;
// Use your own consumer key (this is not a valid consumer key)
http.OAuthConsumerKey := '123abc';
http.OAuthSigMethod := 'RSA-SHA256';
success := http.SetOAuthRsaKey(privKey);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
// Tell Chilkat to automatically calculate and add the oauth_body_hash field when sending the request.
http.OAuthBodyHash := True;
// Send this request to an endpoint at chilkatsoft.com. The purpose of this example is to show
// how the OAuth1.0a Authorization header is computed and sent by Chilkat.
// The chilkatsoft.com site itself doesn't do OAuth1. It's just ignoring the Authorization header.
resp := THttpResponse.Create;
success := http.HttpStr('POST','https://chilkatsoft.com/echo_request_body.asp','<notUsed>123</notUsed>','utf-8','application/xml',resp);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
// Examine the request header we just sent..
WriteLn(http.LastHeader);
// Sample output:
// POST /echo_request_body.asp HTTP/1.1
// Host: chilkatsoft.com
// Accept: */*
// Accept-Encoding: gzip
// Content-Type: application/xml
// Content-Length: 22
// Authorization: OAuth oauth_consumer_key="123abc", oauth_nonce="A2E91C3B53E0BD7FBF71F441336679E358DDCEEE", oauth_body_hash="a5kPTsDwUwmBjC0voNlAAvM6YoaRS5X7sTO49jl3/h8=", oauth_timestamp="1756324932", oauth_signature_method="RSA-SHA256", oauth_version="1.0", oauth_signature="*****"
pfx.Free;
privKey.Free;
http.Free;
resp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.