Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

DataWeave module providing HMAC and RSA JSON Web Token signing.

Notifications You must be signed in to change notification settings

mulesoft-consulting/jwt-dw-module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Publish GitHub Package Unit Test Module

DataWeave JWT Module

This module provides functionality to create signed JSON Web Tokens. The following formats are currently support:

  • HS256
  • HS384
  • HS512
  • RS256
  • RS384
  • RS512

RSA private keys must be in PKCS#1 or PKCS#8 format.

Example RSA usage:

%dw 2.0
output application/java
import jwt::RSA
---
{
	token: RSA::JWT(
		{
			iss: p('google.clientEmail'),
			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' }
		},
		p('google.privateKey')
	),
	expiration: now() + |PT3550S|
}

Example HMAC usage:

%dw 2.0
import jwt::HMAC
output application/json
---
HMAC::JWT({
            "firstName": "Michael",
            "lastName": "Jones"
          }, "Mulesoft123!")

jwt::HMAC Functions

Valid Algorithms

  • HS256
  • HS384
  • HS512

NOTE: Header typ and alg keys will be added/overriden automatically

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

Returns a signed JSON web token with the specified header and payload (body), signed using signingKey and algorithm specified by algorithm.


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

Returns a signed JSON web token with the specified header and payload (body), signed using signingKey via the HMAC-SHA256 (HS256) algorithm.


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

Returns a signed JSON web token with the specified payload (body), signed using signingKey via the HMAC-SHA256 (HS256) algorithm. Header is defaulted as { "alg": "HS256", "typ": "JWT" }


jwt::RSA Functions

Valid Algorithms

  • RS256
  • RS384
  • RS512

NOTE: Header typ and alg keys will be added/overriden automatically

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

Returns a signed JSON web token with the specified header and payload (body), signed using PKCS#1 or PKCS#8 privateKey and algorithm specified by algorithm.


JWT(payload: Object, privateKey: String): String_

Returns a signed JSON web token with the specified header and payload (body), signed using PKCS#1 or PKCS#8 privateKey and algorithm HMAC-SHA256.

About

DataWeave module providing HMAC and RSA JSON Web Token signing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages