Web Connection
AddHeader - Authorization
Gravatar is a globally recognized avatar based on your email address. AddHeader - Authorization
  Joy Tan
  All
  Nov 10, 2021 @ 04:27pm

HI Rick,

How do I code this, do I use AppendHeader?

var sha256 = require('sha256');

var seed = "abcdefghijklmnop"
var apikey = "_V87Qtb513Cd3vabM7RC0TbtJWeSo8p7"
var apipin = "123456"
var prehash = apikey + seed + apipin;
var apihash = 's2/'+ seed + '/' + sha256(prehash);
var authKey = new Buffer(apikey + ":" + apihash).toString('base64')
console.log("Authorization: Basic " + authKey);

ocodeit = CREATEOBJECT('wwencryption')
lcseed = "321456789012345678901234567890"
lcapikey = "<mykey>"
lcapipin = "<mypin>"
lcprehash = lcapikey + lcseed + lcapipin
lccoded = ocodeit.ComputeHash(lcprehash,"HMACSHA256",lcseed)
lcapihash = 's2/' + lcseed + '/' + lccoded

oHTTP.AppendHeader("x-custom","Custom Header")
oHTTP.AppendHeader("Authorization",lcapihash)




Thanks, Joy

Gravatar is a globally recognized avatar based on your email address. re: AddHeader - Authorization
  Joy Tan
  Joy Tan
  Nov 10, 2021 @ 05:46pm

HI Rick,

Basically my confusion on building this is the sha256()

var apihash = 's2/'+ seed + '/' + sha256(prehash);
var authKey = base64Encode(apikey + ':' + apihash)

In your class wwencryption, provide the equivalent with ComputeHash? set classlib to wwencryption otest = createobject("wwencryption") ? otest.ComputeHash(prehash, "SHA256", seed)

Second question: what about the equivalent of base64Encode? Is that the same as Strconv(apikey + ':' + apihash,13)?

Thanks, Joy

Gravatar is a globally recognized avatar based on your email address. re: AddHeader - Authorization
  Rick Strahl
  Joy Tan
  Nov 11, 2021 @ 02:16pm

ComputeHash() by default returns base64 encoded binary data, and optionally can return binHex (which is what FoxPro uses for blob data - basically byte pairs as a string).

+++ Rick ---

© 1996-2021