Can I get some help please taking this jwt encoder over the finish line?

Or more generally, if I may, can I request some love given to JWT stdlib swi offers? All I can find is this with almost no doc and the directory above it gives me Forbidden access denial.

I’m just looking for an encoder and decoder that takes a header, payload, and key and returns a base64 token consistent with the JWT protocol (so preferably eliminates padding, and so forth), and vis versa.

I also did find this but it’s unfortunately quite outdated and I couldn’t get it to work. For example it only supports kty: "oct" for the keytype and not the more secure EC or RSA, and beyond that, when I ran the token through the JWT debugger it gives me “invalid signature” (this is even the case with the sample token they present in the readme).

Anyway I asked chatgpt and after LOAD of “generate code → run it → get an error → show chatgpt → regenerate code” cycles, still couldn’t get it to work.

The closest I got was this

  • https://pastebin.com/QDMWKRsx

but the result you get from this is

{"alg":"HS256","typ":"JWT"}.{"sub":"1234567890","name":"John Doe","iat":1516239022}
..o—6kgõëgõ÷·5õÝ;kWßv¸m¦¸ÛÝÛÛ­µï¦üߧáÖ÷ãÝüñÍ×û
true.

which obviously does not look correct. Can I get some assistance with this please?

Have you seen the crypto-signatures docs: SWI-Prolog -- Manual

I have, but I’m really not sure how to implement the encoder on my own. I was hoping some uber nerds here could assist :smiley: . Can you recommend a good guide or tutorial on implementing a jwt encoder/decoder using the predicates available there?

There is no JWT support in the SWI-Prolog standard lib. Seems the work of Wouter is a good start and could be extended with new algorithms from the OpenSSL crypto binding. If someone fancies to put it all together, I’m happy to add it to the libraries.

Note that SWI-Prolog Solutions can implement such libraries commercially. In cases like this, probably as open source extension.

1 Like