Giter Site home page Giter Site logo

wphampton / jsonwebtokens.cfc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bennadel/jsonwebtokens.cfc

0.0 1.0 0.0 340 KB

Thi is a ColdFusion gateway to help encode and decode JSON web tokens.

License: Other

ColdFusion 73.80% CSS 20.47% JavaScript 5.73%

jsonwebtokens.cfc's Introduction

JSONWebTokens.cfc - A ColdFusion Gateway For JSON Web Tokens

by Ben Nadel (on Google+)

This is a small ColdFusion module to facilitate the encoding and decoding of JSON Web Tokens, or JWT. In order to start working with JSON Web Tokens, you can either use the .encode() and .decode() methods provided by the core gateway:

var jwt = new lib.JsonWebTokens();

var jwtToken = jwt.encode( somePayload, "HS256", "secretKey" );
var payload = jwt.decode( jwtToken, "HS256", "secretKey" );

Or, if you intend to use the same encoding and decoding methods over and over again in a particular application, it can be more efficient to instantiate and cache a JSON Web Token client:

var client = new lib.JsonWebTokens().createClient( "HS256", "secretKey" );

var jwtToken = client.encode( somePayload );
var payload = client.decode( jwtToken );

By doing this, you can pass around your JWT implementation without having to pass around your secret key or your signing algorithm.

Security

At this time, the ColdFusion JSON Web Token library supports both Hmac and RSA based signing:

  • HS256 ( uses HmacSHA256 as the underlying Java algorithm).
  • HS384 ( uses HmacSHA384 as the underlying Java algorithm).
  • HS512 ( uses HmacSHA512 as the underlying Java algorithm).
  • RS256 ( uses SHA256withRSA as the underlying Java algorithm).
  • RS384 ( uses SHA384withRSA as the underlying Java algorithm).
  • RS512 ( uses SHA512withRSA as the underlying Java algorithm).

However, since the round-trip RSA encryption algorithm requires both a public key (for verification) and a private key (for signing), the private key is required when using RSA-based methods or creating an RSA-based client:

// Create an Hmac-based client.
var client = new lib.JsonWebTokens().createClient( "HS256", "secret" );

// Create an RSA-based client.
var client = new lib.JsonWebTokens().createClient( "RS256", "publicKey", "privateKey" );

// Or, just use the .encode() and .decode() methods directly:
var jwt = new lib.JsonWebTokens();

// Encode a payload:
jwt.encode( somePayload, "HS256", "secretKey" );
jwt.encode( somePayload, "RS256", "publicKey", "privateKey" );

// Decode a payload:
jwt.decode( jwtToken, "HS256", "secretKey" );
jwt.decode( jwtToken, "RS256", "publicKey", "privateKey" );

When using the RSA encryption algorithm, the public and private keys are assumed to be provided in plain-text PEM format.

NOTE: PEM (Privacy Enhanced Mail) format is a Base64 encoded DER certificate commonly used on servers.

The JSON Web Token library prevent anonymous / pre-verified tokens, and for security purposes, never uses the algorithm presented in the header. All decoding / verifying is required to use the internal signer with a specific algorithm so as to prevent abuse.

jsonwebtokens.cfc's People

Contributors

bennadel avatar wphampton avatar rayvarner avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.