JWT
JWT module for BoxLang providing complete JWS signing, JWE encryption, and a fluent token builder with RFC 7518 / RFC 7519 compliance.
Last updated
Was this helpful?
Was this helpful?
# Operating Systems using the Quick Installer
install-bx-module bx-jwt
# Using CommandBox for web servers
box install bx-jwtsecret = jwtGenerateSecret( 256 );
token = jwtCreate( { sub: "user-123", iss: "my-api", roles: [ "admin" ] }, secret, "HS256" );
payload = jwtVerify( token, secret, "HS256" );
writeOutput( payload.sub ); // user-123keys = jwtGenerateKeyPair( "RS256" );
token = jwtCreate( { sub: "user-123" }, keys.privateKey, "RS256" );
payload = jwtVerify( token, keys.publicKey, "RS256" );token = jwtNew()
.subject( "user-123" )
.issuer( "my-api" )
.audience( "mobile-client" )
.claim( "roles", [ "admin", "user" ] )
.expireIn( 3600 )
.header( "kid", "v1" )
.sign( secret, "HS256" );token = jwtEncrypt( { sub: "user-123", ssn: "123-45-6789" }, secret, { keyAlgorithm: "dir", encAlgorithm: "A256GCM" } );
payload = jwtDecrypt( token, secret, { keyAlgorithm: "dir", encAlgorithm: "A256GCM" } );