DataWeave JWT Library
RSA
jwt::RSA
This module provides functionality to create signed JSON Web Tokens using RSA signatures.
The supported RSA algorithms are:
- RS256
- RS384
- RS512
RSA private keys must be in PKCS#1
or PKCS#8
format.
Index
Functions
Name | Description |
---|---|
JWT | Generate JWT with header, payload, and signature by specific algorithm. |
alg | Helper function to validate the algorithm provided for signing. |
signJWT | Helper function to sign the JWT. |
Variables
Name | Description |
---|---|
algMapping | Supported RSA algorithms. |
Functions
JWT ↑↑
JWT(header: Object, payload: Object, signingKey: String, algorithm: String): String
Generate JWT with header, payload, and signature by specific algorithm.
Parameters
Name | Type | Description |
---|---|---|
header | Object | JWT header. |
payload | Object | JWT payload. |
signingKey | String | Signing key. |
algorithm | String | RSA algorithm. |
Example
This example shows how the JWT
behaves with the sample input.
Source
%dw 2.0
import * from jwt::RSA
output application/json
input key application/json
---
{
token: JWT(
{
header: "value"
},
{
iss: "some@email.com",
aud: 'https://oauth2.googleapis.com/token',
scope: 'https://www.googleapis.com/auth/drive.readonly',
iat: now() as Number { unit: 'seconds' },
exp: (now() + |PT3600S|) as Number { unit: 'seconds' }
},
key,
'Sha384withRSA'
),
expiration: now() + |PT3550S|
}
Output
{
token: "eyJhbGCI6IkpXVCJ9.eyJ4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN_oWnFSRgCz",
"expiration": "2031-11-18T15:11:31.060175Z"
}
JWT(payload: Object, signingKey: String): String
Generate JWT with a payload, automatically generated header, and key signed with RS256.
Parameters
Name | Type | Description |
---|---|---|
payload | Object | JWT payload. |
signingKey | String | Signing key. |
Example
This example shows how the JWT
behaves with the sample input.
Source
%dw 2.0
import * from jwt::RSA
output application/json
input key application/json
---
{
token: JWT(
{
iss: "some@email.com",
aud: 'https://oauth2.googleapis.com/token',
scope: 'https://www.googleapis.com/auth/drive.readonly',
iat: now() as Number { unit: 'seconds' },
exp: (now() + |PT3600S|) as Number { unit: 'seconds' }
},
key
),
expiration: now() + |PT3550S|
}
Output
{
token: "eyJhbGCI6IkpXVCJ9.eyJ4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN_oWnFSRgCz",
"expiration": "2031-11-18T15:11:31.060175Z"
}
alg ↑↑
alg(algorithm: String): String | Null
Helper function to validate the algorithm provided for signing.
Parameters
Name | Type | Description |
---|---|---|
algorithm | String | Algorithm provided for signing. |
signJWT ↑↑
signJWT(jwt: String, privateKey: String, algorithm: String): String
Helper function to sign the JWT.
Parameters
Name | Type | Description |
---|---|---|
jwt | String | Header and payload parts of the JWT. |
privateKey | String | Signing key. |
algorithm | String | Algorithm provided for signing. |
Variables
algMapping ↑↑
Supported RSA algorithms.