Lazarus Pascal
Lazarus Pascal
Generate OAuth 1.0 Signature
Demonstrates how to generate an OAuth 1.0 signature.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.OAuth1;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
oauth: TOAuth1;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
success := False;
oauth := TOAuth1.Create;
// Set input parameters:
oauth.OauthVersion := '1.0';
oauth.OauthMethod := 'GET';
oauth.OauthUrl := 'http://echo.lab.madgex.com/echo.ashx';
oauth.ConsumerKey := 'key';
oauth.ConsumerSecret := 'secret';
oauth.Token := 'accesskey';
oauth.TokenSecret := 'accesssecret';
oauth.Nonce := '01020304050607080102030405060708';
oauth.Timestamp := '1441659763';
// Can be "HMAC-SHA1", "HMAC-SHA256", "RSA-SHA1", or "RSA-SHA2"
oauth.SignatureMethod := 'HMAC-SHA256';
success := oauth.Generate();
if (success <> True) then
begin
WriteLn(oauth.LastErrorText);
Exit;
end;
// Examine the various outputs:
WriteLn(oauth.QueryString);
WriteLn(oauth.BaseString);
WriteLn(oauth.HmacKey);
WriteLn(oauth.Signature);
WriteLn(oauth.EncodedSignature);
WriteLn(oauth.AuthorizationHeader);
WriteLn(oauth.GeneratedUrl);
oauth.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.