API needs SHA256 HMAC

Have an API that wants an auth key as
$auth_token = hash_hmac('sha256', $timestamp, $api_key);

Am I able to replicate something like this server side in the current Wappler
@patrick

Not at computer but have you tried setting the parameter to something like

now.sha256(api_key)

Sorry try that

Will try it quickly, I tried a few things, but as far as I have read the normal SHA256 can not produce the same as the HMAC standard should.
Will test that and let you know.

Looks like no matter what variation of SHA256 i try it does not give the correct result.
Even testing with the online generator tools with the same data in the online HMAC version vs the normal version i get completely different results.
The normal online SHA256 with SALT generator gives the same as Wappler while the HMAC online version gives the same as what the API is asking for.

Going to have to either make a custom formatter or wait for Wappler to add it in their cryptography.

Literally on the back on an envelope what about a custom formatter like this (may have to check a bit of syntax)

namespace lib/core

Function formatter_hmac($api_key)
$val = hash_hmac(date(Y-m-d HH:mm),$api_key)
return $val
(sorry, phone keeps capitalising things)

I would advise to use strval($api_key) to make sure it’s always treated as a string.

1 Like

never used a custom formatter before, so sadly am going to need an explanation like you are explaining this to a toddler, how, where, what, why, who, when, etc. lol. pleeeesae

This is also interesting

Just to confirm, this is a server side formatter i need?

Where do you need it?

Yes, instructions here

1 Like

query parameter of a server side API action for auth=432hjkl423709hklmn32l489

Didn’t you just answer yourself? :joy:

Lol, no, confushious say whaat

Do my original notes help :roll_eyes:

2 Likes

Query parameter of a server side API Action for auth=$auth_token
$auth_token = hash_hmac(‘sha256’, $timestamp, $api_key);

What Brian said a few posts ago but I would say that:

hash_hmac( ‘sha256’ , strval($api_key))

1 Like

Lol,yeah, forgot to specify the encryption

1 Like

ok gonna try and will bug you if i get stuck

1 Like

LOL…you are actually not asking for the function…it’s already in the OP. I just noticed.

Yeah. Custom formatter all the way…I use quite a few. You won’t have any trouble with them.