Secret Management for JWT Secure APIs
Posted: Fri Sep 13, 2024 7:11 am
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
And also the code for validating the JWT Token
I have this routines in the same server module asociated to an API, all was generated automatically for LANSA API template
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 )
EndifCode: 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