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
(Lianja) Walmart Partner API Authentication (Generate a Signature for a Request)Demonstrates how to generate a signature for a Walmart Partner REST API call.
// This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. lcConsumerId = "b68d2a72...." lcBaseUrl = "https://marketplace.walmartapis.com/v2/feeds" // This is your Base64 encoded private key lcPrivateEncodedStr = "MIICeAIBADANBgkqhkiG9w0BAQEFAA......" lcHttpMethod = "GET" // We need a timestamp in decimal string form representing the number of milliseconds since Jan 01 1970 UTC. loDt = createobject("CkDateTime") // Set bLocal = .T. for a timestamp in the local timezone. Set bLocal = .F. for a UTC timestamp. llBLocal = .F. // This gets the timestamp in seconds, not milliseconds. lnTimeStampVal = loDt.GetAsUnixTime(llBLocal) // Build the string to sign. loSbStringToSign = createobject("CkStringBuilder") loSbStringToSign.Append(lcConsumerId) loSbStringToSign.Append(Chr(10)) loSbStringToSign.Append(lcBaseUrl) loSbStringToSign.Append(Chr(10)) loSbStringToSign.Append(lcHttpMethod) loSbStringToSign.Append(Chr(10)) loSbStringToSign.AppendInt(lnTimeStampVal) // 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). loSbStringToSign.Append("000" + Chr(10)) loPrivKey = createobject("CkPrivateKey") // 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. llSuccess = loPrivKey.LoadPem(lcPrivateEncodedStr) if (llSuccess <> .T.) then ? loPrivKey.LastErrorText release loDt release loSbStringToSign release loPrivKey return endif loRsa = createobject("CkRsa") llSuccess = loRsa.ImportPrivateKeyObj(loPrivKey) if (llSuccess <> .T.) then ? loRsa.LastErrorText release loDt release loSbStringToSign release loPrivKey release loRsa return endif // We want a base64 signature string. loRsa.EncodingMode = "base64" lcSignatureString = loRsa.SignStringENC(loSbStringToSign.GetAsString(),"SHA256") if (loRsa.LastMethodSuccess <> .T.) then ? loRsa.LastErrorText release loDt release loSbStringToSign release loPrivKey release loRsa return endif ? "Signature String: " + lcSignatureString release loDt release loSbStringToSign release loPrivKey release loRsa |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.