Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Walmart Partner API Authentication (Generate a Signature for a Request)Demonstrates how to generate a signature for a Walmart Partner REST API call.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess String sConsumerId String sBaseUrl String sPrivateEncodedStr String sHttpMethod Handle hoDt Boolean iBLocal Integer iTimeStampVal Handle hoSbStringToSign Variant vPrivKey Handle hoPrivKey Handle hoRsa String sSignatureString String sTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Move "b68d2a72...." To sConsumerId Move "https://marketplace.walmartapis.com/v2/feeds" To sBaseUrl // This is your Base64 encoded private key Move "MIICeAIBADANBgkqhkiG9w0BAQEFAA......" To sPrivateEncodedStr Move "GET" To sHttpMethod // We need a timestamp in decimal string form representing the number of milliseconds since Jan 01 1970 UTC. Get Create (RefClass(cComCkDateTime)) To hoDt If (Not(IsComObjectCreated(hoDt))) Begin Send CreateComObject of hoDt End // Set bLocal = True for a timestamp in the local timezone. Set bLocal = False for a UTC timestamp. Move False To iBLocal // This gets the timestamp in seconds, not milliseconds. Get ComGetAsUnixTime Of hoDt iBLocal To iTimeStampVal // Build the string to sign. Get Create (RefClass(cComChilkatStringBuilder)) To hoSbStringToSign If (Not(IsComObjectCreated(hoSbStringToSign))) Begin Send CreateComObject of hoSbStringToSign End Get ComAppend Of hoSbStringToSign sConsumerId To iSuccess Get ComAppend Of hoSbStringToSign (character(10)) To iSuccess Get ComAppend Of hoSbStringToSign sBaseUrl To iSuccess Get ComAppend Of hoSbStringToSign (character(10)) To iSuccess Get ComAppend Of hoSbStringToSign sHttpMethod To iSuccess Get ComAppend Of hoSbStringToSign (character(10)) To iSuccess Get ComAppendInt Of hoSbStringToSign iTimeStampVal To iSuccess // We add three zero's so that the timestamp value is in milliseconds. // We don't care about accuracy down to less than a second. // All the server cares about is that the request was signed at the current date/time // within some reasonable margin of error (to account for systems having clocks // that may be slightly different). Get ComAppend Of hoSbStringToSign "000" + (character(10)) To iSuccess Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey If (Not(IsComObjectCreated(hoPrivKey))) Begin Send CreateComObject of hoPrivKey End // Load the private key into a private key object. // Note: Technically the private key is not PEM because it lacks the header/footer strings // used for PEM. However, the LoadPem method will still accept it and load it correctly. Get ComLoadPem Of hoPrivKey sPrivateEncodedStr To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoPrivKey To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatRsa)) To hoRsa If (Not(IsComObjectCreated(hoRsa))) Begin Send CreateComObject of hoRsa End Get pvComObject of hoPrivKey to vPrivKey Get ComImportPrivateKeyObj Of hoRsa vPrivKey To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoRsa To sTemp1 Showln sTemp1 Procedure_Return End // We want a base64 signature string. Set ComEncodingMode Of hoRsa To "base64" Get ComGetAsString Of hoSbStringToSign To sTemp1 Get ComSignStringENC Of hoRsa sTemp1 "SHA256" To sSignatureString Get ComLastMethodSuccess Of hoRsa To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoRsa To sTemp1 Showln sTemp1 Procedure_Return End Showln "Signature String: " sSignatureString End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.