DataWeave JWT Library
HMAC
jwt::HMAC
This module provides functionality to create signed JSON Web Tokens using HMAC.
The supported HMAC algorithms are:
- HS256
- HS384
- HS512
Index
Functions
Name | Description |
---|---|
JWT | Generate JWT with header, payload, and signature by specific algorithm. |
alg | Helper function to validate algorithm provided for signing. |
signJWT | Helper function to sign the JWT. |
Variables
Name | Description |
---|---|
algMapping | Supported HMAC 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 | HMAC algorithm. |
Example
This example shows how JWT
behaves with the sample input.
Source
%dw 2.0
%dw 2.0
import jwt::HMAC
output application/json
---
HMAC::JWT({
"header": "value"
},
{
"firstName": "Michael",
"lastName": "Jones"
}, "secret", "HmacSHA384")
Output
"eyJhbGCI6IkpXVCJ9.eyJ4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN_oWnFSRgCz"
JWT(header: Object, payload: Object, signingKey: String): String
Generate JWT with a header, payload, and key signed with HMAC-SHA256.
Parameters
Name | Type | Description |
---|---|---|
header | Object | JWT header. |
payload | Object | JWT paylaod. |
signingKey | String | Signing key. |
Example
This example shows how JWT
behaves with the sample input.
Source
%dw 2.0
import jwt::HMAC
output application/json
---
HMAC::JWT({
"header": "value"
},
{
"firstName": "Michael",
"lastName": "Jones"
}, "secret")
Output
"eyJhbGCI6IkpXVCJ9.eyJ4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN_oWnFSRgCz"
JWT(payload: Object, signingKey: String): String
Generate JWT with a payload, automatically generated header, and key signed with HMAC-SHA256.
Parameters
Name | Type | Description |
---|---|---|
payload | Object | JWT payload. |
signingKey | String | Signing key. |
Example
This example shows how JWT
behaves with the sample input.
Source
%dw 2.0
import jwt::HMAC
output application/json
---
HMAC::JWT({
"firstName": "Michael",
"lastName": "Jones"
}, "secret")
Output
"eyJhbGCI6IkpXVCJ9.eyJ4iLCJpYXQiOjE0MjI3Nzk2Mzh9.gzSraSYS8EXBxLN_oWnFSRgCz"
alg ↑↑
alg(algorithm: String): String | Null
Helper function to validate algorithm provided for signing.
Parameters
Name | Type | Description |
---|---|---|
algorithm | String | Algorithm provided for signing. |
signJWT ↑↑
signJWT(content: String, key: String, alg: String): String
Helper function to sign the JWT.
Parameters
Name | Type | Description |
---|---|---|
content | String | JWT content. |
key | String | Signing key. |
alg | String | HMAC algorithm. |
Variables
algMapping ↑↑
Supported HMAC algorithms.