DataWeave JWT Library icon

DataWeave JWT Library

(2 reviews)

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

NameDescription
JWTGenerate JWT with header, payload, and signature by specific algorithm.
algHelper function to validate algorithm provided for signing.
signJWTHelper function to sign the JWT.

Variables

NameDescription
algMappingSupported 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
NameTypeDescription
headerObjectJWT header.
payloadObjectJWT payload.
signingKeyStringSigning key.
algorithmStringHMAC 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
NameTypeDescription
headerObjectJWT header.
payloadObjectJWT paylaod.
signingKeyStringSigning 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
NameTypeDescription
payloadObjectJWT payload.
signingKeyStringSigning 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
NameTypeDescription
algorithmStringAlgorithm provided for signing.

signJWT ↑↑

signJWT(content: String, key: String, alg: String): String

Helper function to sign the JWT.

Parameters
NameTypeDescription
contentStringJWT content.
keyStringSigning key.
algStringHMAC algorithm.

Variables

algMapping ↑↑

Supported HMAC algorithms.


Reviews

TypeDataWeave Library
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onMar 23, 2022
Asset overview

Asset versions for 1.0.x

Asset versions
VersionActions
1.0.0