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
(PowerBuilder) Walmart Partner API Authentication (Generate a Signature for a Request)Demonstrates how to generate a signature for a Walmart Partner REST API call.
integer li_rc integer li_Success string ls_ConsumerId string ls_BaseUrl string ls_PrivateEncodedStr string ls_HttpMethod oleobject loo_Dt integer li_BLocal integer li_TimeStampVal oleobject loo_SbStringToSign oleobject loo_PrivKey oleobject loo_Rsa string ls_SignatureString // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. ls_ConsumerId = "b68d2a72...." ls_BaseUrl = "https://marketplace.walmartapis.com/v2/feeds" // This is your Base64 encoded private key ls_PrivateEncodedStr = "MIICeAIBADANBgkqhkiG9w0BAQEFAA......" ls_HttpMethod = "GET" // We need a timestamp in decimal string form representing the number of milliseconds since Jan 01 1970 UTC. loo_Dt = create oleobject // Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 li_rc = loo_Dt.ConnectToNewObject("Chilkat.CkDateTime") if li_rc < 0 then destroy loo_Dt MessageBox("Error","Connecting to COM object failed") return end if // Set bLocal = 1 for a timestamp in the local timezone. Set bLocal = 0 for a UTC timestamp. li_BLocal = 0 // This gets the timestamp in seconds, not milliseconds. li_TimeStampVal = loo_Dt.GetAsUnixTime(li_BLocal) // Build the string to sign. loo_SbStringToSign = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbStringToSign.ConnectToNewObject("Chilkat.StringBuilder") loo_SbStringToSign.Append(ls_ConsumerId) loo_SbStringToSign.Append("~n") loo_SbStringToSign.Append(ls_BaseUrl) loo_SbStringToSign.Append("~n") loo_SbStringToSign.Append(ls_HttpMethod) loo_SbStringToSign.Append("~n") loo_SbStringToSign.AppendInt(li_TimeStampVal) // 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). loo_SbStringToSign.Append("000~n") loo_PrivKey = create oleobject // Use "Chilkat_9_5_0.PrivateKey" for versions of Chilkat < 10.0.0 li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey") // 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. li_Success = loo_PrivKey.LoadPem(ls_PrivateEncodedStr) if li_Success <> 1 then Write-Debug loo_PrivKey.LastErrorText destroy loo_Dt destroy loo_SbStringToSign destroy loo_PrivKey return end if loo_Rsa = create oleobject // Use "Chilkat_9_5_0.Rsa" for versions of Chilkat < 10.0.0 li_rc = loo_Rsa.ConnectToNewObject("Chilkat.Rsa") li_Success = loo_Rsa.ImportPrivateKeyObj(loo_PrivKey) if li_Success <> 1 then Write-Debug loo_Rsa.LastErrorText destroy loo_Dt destroy loo_SbStringToSign destroy loo_PrivKey destroy loo_Rsa return end if // We want a base64 signature string. loo_Rsa.EncodingMode = "base64" ls_SignatureString = loo_Rsa.SignStringENC(loo_SbStringToSign.GetAsString(),"SHA256") if loo_Rsa.LastMethodSuccess <> 1 then Write-Debug loo_Rsa.LastErrorText destroy loo_Dt destroy loo_SbStringToSign destroy loo_PrivKey destroy loo_Rsa return end if Write-Debug "Signature String: " + ls_SignatureString destroy loo_Dt destroy loo_SbStringToSign destroy loo_PrivKey destroy loo_Rsa |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.