Xbase++ Requires Chilkat v11.0.0+
Xbase++
ABN AMRO Create Signed JSON Web Token
See more ABN AMRO Examples
Demonstrates how to create a signed JWT to be used for authenticating requests to the ABN AMRO REST API's.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRsa
LOCAL oPrivkey
LOCAL oPubkey
LOCAL oJwt
LOCAL oJsonHeader
LOCAL oJsonPayload
LOCAL nCurDateTime
LOCAL cJwtStr
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Create public/private key pair (RSA)
oRsa := CreateObject("Chilkat.Rsa")
// Generate a 2048-bit key.
oPrivkey := CreateObject("Chilkat.PrivateKey")
nSuccess := oRsa:GenKey(2048, oPrivkey)
IF (nSuccess == 0)
? oRsa:LastErrorText
oRsa:destroy()
oPrivkey:destroy()
RETURN
ENDIF
// Export the key to PEM files.
// Write one PEM file for the private key, and one for the public key.
nSuccess := oPrivkey:SavePemFile("qa_data/pem/abnAmroPrivateKey.pem")
oPubkey := CreateObject("Chilkat.PublicKey")
oPrivkey:ToPublicKey(oPubkey)
nSuccess := oPubkey:SavePemFile(1, "qa_data/pem/abnAmroPublicKey.pem")
// Note: Please share your public key along with your app name and developer email id at api.support@nl.abnamro.com.
// Token generation will not work unless public key is associated with your app.
// Create the JWT.
oJwt := CreateObject("Chilkat.Jwt")
// Create the header:
// {
// "typ": "JWT",
// "alg": "RS256"
// }
oJsonHeader := CreateObject("Chilkat.JsonObject")
oJsonHeader:UpdateString("typ", "JWT")
oJsonHeader:UpdateString("alg", "RS256")
// Create the payload:
// {
// "nbf": 1499947668,
// "exp": 1499948668,
// "iss": "me",
// "sub": "anApiKey",
// "aud": "https://auth-sandbox.abnamro.com/oauth/token"
// }
oJsonPayload := CreateObject("Chilkat.JsonObject")
nCurDateTime := oJwt:GenNumericDate(0)
// Set the "not process before" timestamp to now.
nSuccess := oJsonPayload:AddIntAt(-1, "nbf", nCurDateTime)
// Set the timestamp defining an expiration time (end time) for the token
// to be now + 1 hour (3600 seconds)
nSuccess := oJsonPayload:AddIntAt(-1, "exp", nCurDateTime + 3600)
oJsonPayload:UpdateString("iss", "me")
oJsonPayload:UpdateString("sub", "anApiKey")
oJsonPayload:UpdateString("aud", "https://auth-sandbox.abnamro.com/oauth/token")
// Produce the smallest possible JWT:
oJwt:AutoCompact := 1
cJwtStr := oJwt:CreateJwtPk(oJsonHeader:Emit(), oJsonPayload:Emit(), oPrivkey)
IF (oJwt:LastMethodSuccess == 0)
? oJwt:LastErrorText
oRsa:destroy()
oPrivkey:destroy()
oPubkey:destroy()
oJwt:destroy()
oJsonHeader:destroy()
oJsonPayload:destroy()
RETURN
ENDIF
// Here is the JWT:
? cJwtStr
oRsa:destroy()
oPrivkey:destroy()
oPubkey:destroy()
oJwt:destroy()
oJsonHeader:destroy()
oJsonPayload:destroy()