Create JWT Token with certificate

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
dominique
Posts: 33
Joined: Mon May 29, 2017 4:16 pm
Location: St. Gallen, Switzerland

Create JWT Token with certificate

Post by dominique » Sat Feb 13, 2021 12:13 am

We need to create a JWT Token with RS512 encryption. Therefore we haveto deal with #PRIM_CAPI.PrivateKey and #PRIM_CAPI.Publickey.

Symetric encryption works fine

Code: Select all

Mthroutine Name(CreateJWTSymetric)
Define_Map For(*INPUT) Class(#PRIM_BOLN) Name(#I_RS)

Define_Com Class(#prim_srvm.HttpJsonWebToken) Name(#jwt)
Define_Com Class(#prim_srvm.HttpJsonWebTokenSignatureHSnnn) Name(#IssuerHS)
Define_Com Class(#prim_dc.UnicodeString) Name(#unicodestr)
Define Field(#BinarySecret) Type(*BIN) Length(128)

#jwt.SubjectClaim := "subject"
#jwt.IssuerClaim := "issuer"
#jwt.IssuedAtClaim := *DATETIME
#jwt.NotBeforeClaim := *DATETIME
#jwt.IssueTokenTimespan := 1

#jwt.Claims.AddStringMember( "contractid" "2345" )


#IssuerHS.Algorithm := HS256
#BinarySecret := test
#IssuerHS.IssueToken Jsonwebtoken(#jwt) Secret(#BinarySecret) Result(#unicodestr)
Endroutine

How to do this with certificate based encryption? Does anyone have experience/examples or recommendations?

Code: Select all

Mthroutine Name(CreateJWTAsymetric)
Define_Com Class(#prim_dc.UnicodeString) Name(#unicodestr)
Define_Com Class(#prim_srvm.HttpJsonWebToken) Name(#jwt)
Define_Com Class(#prim_srvm.HttpJsonWebTokenSignatureRSnnn) Name(#IssuerRS)

Define_Com Class(#PRIM_CAPI.PrivateKey) Name(#privateKey)
Define_Com Class(#PRIM_CAPI.PublicKey) Name(#publicKey)



#jwt.SubjectClaim := "subject"
#jwt.IssuerClaim := "issuer"
#jwt.IssuedAtClaim := *DATETIME
#jwt.NotBeforeClaim := *DATETIME
#jwt.IssueTokenTimespan := 1

#jwt.Claims.AddStringMember( "contractid" "2345" )


#IssuerRS.Algorithm := RS512

* How to handle?
* #publicKey.LoadPemFile
* #privateKey.LoadEncryptedPemFile
* #IssuerRS.IssueToken Privatekey() Result(#unicodestr)
Endroutine

thanks

Post Reply