Secret Management for JWT Secure APIs

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Davinchi104
Posts: 4
Joined: Wed Feb 14, 2024 12:28 am

Secret Management for JWT Secure APIs

Post by Davinchi104 »

I am working on the creation of Secure APIs, I followed the documentation given by LANSA, but I don't now how to manage the "Secrets" for generating the signature and the validation for the JWT tokens, currently the secret is writen on the program, ¿ Is there any sugestion for saving this secrets and improve the security of the services ?.

Share with you the code for generating the JWT Token

Code: Select all

If (#jwt.Claims<"Username"> *IsNot *Null)

#JsonBody.Username := #jwt.Claims<"Username">.AsString
#JsonBody.AccessToken := #HSnnn.IssueToken( #jwt "SECRET" )

#Operation.Response.SetContentJson( #JsonBody )
Endif
And also the code for validating the JWT Token

Code: Select all

If (#HSnnn.TryVerifyToken( #Security.HttpBearer.Value, #jwt, "SECRET" ))

If (#jwt.Claims<"Username"> *IsNot *Null)

#Verified := true
#FZUsuario := #jwt.Claims<"Username">.AsString
Endif

Endif
I have this routines in the same server module asociated to an API, all was generated automatically for LANSA API template
Catt
Posts: 8
Joined: Mon Jun 10, 2019 8:00 pm

Re: Secret Management for JWT Secure APIs

Post by Catt »

You might want to consider soft coding the secret and having it stored in an encrypted table. Then you can retrieve it using a fetch from the table.
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Secret Management for JWT Secure APIs

Post by Dino »

Soft coding it in encrypted in a table also gives you the opportunity to change it periodically.

You can have one server module dedicated to generate the token and process those request. So the other server modules just verify it.
Speedlime
Posts: 43
Joined: Wed Feb 03, 2021 2:52 am

Re: Secret Management for JWT Secure APIs

Post by Speedlime »

If you are running on a iSeries, you can use a DTAARA on the server to store it.
Just retrieve from there using BIF.
Davinchi104
Posts: 4
Joined: Wed Feb 14, 2024 12:28 am

Re: Secret Management for JWT Secure APIs

Post by Davinchi104 »

Dino wrote: Sat Sep 14, 2024 11:30 pm Soft coding it in encrypted in a table also gives you the opportunity to change it periodically.

You can have one server module dedicated to generate the token and process those request. So the other server modules just verify it.
Hi Dino, Do you know If there's a documention reference for following this strategy ? I can't find the documentation for creating the encrypted Table
Post Reply