Welcome! Log In Create A New Profile

Advanced

jwt creation

Posted by spyryl 
jwt creation
June 19, 2019 07:09PM
Greetings Gang!!!

Does anyone know how to create a jwt token using WX?

I know that the following is what you use to create the jwt
HMACSHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
password)

now the first 2 are simple as it just looks to be
Encode(header,encodeBASE64)
Encode(payload,encodeBASE64)

but that is where I run into trouble - in WX in order to use HMACSHA256 I need to first hash the password, but that isn't correct as it changes the return values

any assistance with this would be greatly appreciated.

Regards Christo!!!
pao
Re: jwt creation
June 19, 2019 07:46PM
Did you try with:
token is string= Encode(header,encodeBASE64URL) + "." + Encode(payload,encodeBASE64URL) + "." +Encode(HashString(HA_HMAC_SHA_256 , Encode(header,encodeBASE64URL) +"."+ Encode(payload,encodeBASE64URL) , "password"),encodeBASE64URL)

Regards

Paulo Oliveira
Re: jwt creation
June 20, 2019 01:35AM
Paulo, regrettably that didn't seem to work (I can't believe the difficulty I'm having with something that seems so simple.

I use jwt.io to verify whether or not it's a valid token...

Regards C!!!
pao
Re: jwt creation
June 21, 2019 11:45AM
If I use the bellow code and paste the result (ew0KImFsZyI6ICJIUzI1NiIsDQoidHlwIjogIkpXVCINCn0=.ew0KImZpZWxkMSI6ICJteSB0ZXN0IiwNCiJmaWVsZDIiOiAidGVzdCB3aW5kZXYgMjIiLA0KImZpZWxkMyI6IDEyMzQNCn0=.wipr69xJnjaYHn9GACE1K8kRd5QZMStQMKTx-XixBEw=) in [jwt.io] I get Signature Verified .

header is string
payload is string
header=[
{
"alg": "HS256",
"typ": "JWT"
}
]

payload=[
{
"field1": "my test",
"field2": "test windev 22",
"field3": 1234
}
]


token is string= Encode(header,encodeBASE64URL) + "." + Encode(payload,encodeBASE64URL) + "." +Encode(HashString(HA_HMAC_SHA_256 , Encode(header,encodeBASE64URL) +"."+ Encode(payload,encodeBASE64URL) , "your-256-bit-secret"),encodeBASE64URL)

ToClipboard(token)

Regards

Paulo Oliveira



Edited 1 time(s). Last edit at 06/21/2019 11:46AM by pao.
Re: jwt creation
June 21, 2019 12:01PM
Greetings Pao,

I can only get what you've got to work providing I don't have "secret base64 encoded" checked when I paste it in. if it is checked before I paste then it still returns an invalid signature.

the header and payload parts are perfect... it's that damn last bit that is killing it

C!!!
pao
Re: jwt creation
June 21, 2019 12:33PM
I never used it that way but probably in that case you have to encode the secret key to base64 and use the encode result in the hash creation.

Regards

Paulo Oliveira
Re: jwt creation
June 21, 2019 12:48PM
Regrettably - it's not that simple, it's almost like WX doesn't want me to be able to it. it is one of the most frustrating things I've come across.

I have tried it the way you suggested (regrettably to no avail), I'm starting to think I'll need to wait for v25 at this rate sad smiley

C!!!
pao
Re: jwt creation
June 21, 2019 03:11PM
In [jwt.io] if you use the option secret base64 encoded you have to put the secret key in base 64 format.

just use my sample code and in the jwt.oi page paste the JWT generared and put eW91ci0yNTYtYml0LXNlY3JldA== instead of your-256-bit-secret and the signature is valid.

In this case the problem isn't with WX is with the usage of jwt.io

Regards

Paulo Oliveira



Edited 2 time(s). Last edit at 06/21/2019 03:54PM by pao.
Re: jwt creation
June 21, 2019 03:54PM
I need it so I can generate jwt on the fly. regrettably copy'n'paste isn't an actual option.

Fb was a pain in the arse to get working for it's chat bot, but once I figured out the WX version of what they wanted I was able to get that up and running.... this is basically the same scenario, I just need to figure out how WX does the equivalent encryption as what is in the above example

C!!!
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: