Contact Us 1-800-596-4880

JWT

JWT(header: Object, payload: Object, signingKey: String, algorithm: String): String

Generate JWT with header, payload, and signature by specific algorithm.

Introduced in DataWeave version 2.6.0.

Parameters

Name Type Description

header

Object

JWT header.

payload

Object

JWT payload.

signingKey

String

Signing key.

algorithm

String

HMAC algorithm.

Example

This example signs a payload with HS384 and a 384-bit key.

Source

%dw 2.0
import * from dw::util::jwt::HMAC
output application/json
---
JWT({"header": "value"}, {"firstName": "Michael", "lastName": "Jones"},
  "012345678901234567890123456789012345678901234567", "HmacSHA384")

Output

"eyJoZWFkZXIiOiAidmFsdWUiLCJhbGciOiAiSFMzODQiLCJ0eXAiOiAiSldUIn0.eyJmaXJzdE5hbWUiOiAiTWljaGFlbCIsImxhc3ROYW1lIjogIkpvbmVzIn0.F1xP9JjXqmwVfPXULZ7F6EYu2Td36eW4xUWElGHN7ayjWIiBPWM3L4STPQzQ570R"

JWT(header: Object, payload: Object, signingKey: String): String

Generate JWT with a header, payload, and key signed with HMAC-SHA256.

Introduced in DataWeave version 2.6.0.

Parameters

Name Type Description

header

Object

JWT header.

payload

Object

JWT payload.

signingKey

String

Signing key.

Example

This example uses HS256 and a 256-bit key.

Source

%dw 2.0
import * from dw::util::jwt::HMAC
output application/json
---
JWT({"header": "value"}, {"firstName": "Michael", "lastName": "Jones"},
  "01234567890123456789012345678901")

Output

"eyJoZWFkZXIiOiAidmFsdWUiLCJhbGciOiAiSFMyNTYiLCJ0eXAiOiAiSldUIn0.eyJmaXJzdE5hbWUiOiAiTWljaGFlbCIsImxhc3ROYW1lIjogIkpvbmVzIn0.wAoUwkmKhZy6Op119t0N5MwQX-03fJZClzfA5lFwEhg"

JWT(payload: Object, signingKey: String): String

Generate JWT with a payload, automatically generated header, and key signed with HMAC-SHA256.

Introduced in DataWeave version 2.6.0.

Parameters

Name Type Description

payload

Object

JWT payload.

signingKey

String

Signing key.

Example

This example signs a payload with the default HS256 algorithm.

Source

%dw 2.0
import * from dw::util::jwt::HMAC
output application/json
---
JWT({"firstName": "Michael", "lastName": "Jones"},
  "01234567890123456789012345678901")

Output

"eyJhbGciOiAiSFMyNTYiLCJ0eXAiOiAiSldUIn0.eyJmaXJzdE5hbWUiOiAiTWljaGFlbCIsImxhc3ROYW1lIjogIkpvbmVzIn0.JaEz34HXuF4fWg5jM2U9JRnX4vu5twoeDRRg9_anWMc"