jose vs jsonwebtoken
JSON Web Token (JWT) Libraries
josejsonwebtokenSimilar Packages:

JSON Web Token (JWT) Libraries

JSON Web Token (JWT) Libraries are tools that help developers create, sign, verify, and decode JWTs in their applications. These libraries provide functionalities to handle the JWT standard, which is widely used for authentication and information exchange in web applications. They allow for secure transmission of information between parties as a JSON object, ensuring data integrity and authenticity through cryptographic signing. JWT libraries typically support various algorithms for signing tokens, handle token expiration, and provide utilities for parsing and validating tokens. They are essential for implementing stateless authentication, authorization, and secure data exchange in modern web and mobile applications. The jsonwebtoken library is a widely used and feature-rich implementation for working with JWTs in Node.js, offering a simple API for signing, verifying, and decoding tokens. The jose library is a modern and comprehensive implementation of the JOSE (JavaScript Object Signing and Encryption) standards, providing support for JWTs, JWS (JSON Web Signature), JWE (JSON Web Encryption), and JWK (JSON Web Key) with a focus on security, modularity, and performance.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
jose60,225,4907,462258 kB28 days agoMIT
jsonwebtoken37,878,74718,17143.4 kB1914 months agoMIT

Feature Comparison: jose vs jsonwebtoken

Standards Compliance

  • jose:

    The jose library is a comprehensive implementation of the JOSE (JavaScript Object Signing and Encryption) standards, which include JWT (JSON Web Token), JWS (JSON Web Signature), JWE (JSON Web Encryption), and JWK (JSON Web Key). It provides a more complete and standards-compliant solution for working with all aspects of JOSE, making it suitable for applications that require advanced cryptographic features and interoperability.

  • jsonwebtoken:

    The jsonwebtoken library is compliant with the JWT (JSON Web Token) specification, providing a robust implementation for creating, signing, verifying, and decoding JWTs. However, it primarily focuses on JWTs and does not natively support other JOSE (JavaScript Object Signing and Encryption) standards such as JWS (JSON Web Signature) and JWE (JSON Web Encryption).

Modularity

  • jose:

    The jose library is designed with modularity in mind, allowing developers to import only the specific features they need (e.g., JWT, JWS, JWE) rather than the entire library. This modular approach helps reduce the bundle size and improves performance, making it a more efficient choice for modern applications that prioritize lightweight code.

  • jsonwebtoken:

    The jsonwebtoken library is a single, monolithic package that provides all JWT functionalities in one place. While it is easy to use and integrates well into projects, it does not offer modularity, which means that all features are included regardless of whether they are needed, potentially increasing the bundle size.

Cryptographic Algorithms

  • jose:

    The jose library provides support for a comprehensive set of cryptographic algorithms for JWT, JWS, and JWE, including both symmetric and asymmetric algorithms. It also supports modern cryptographic features such as EdDSA (Edwards-Curve Digital Signature Algorithm) and provides a more flexible and extensible architecture for integrating custom algorithms, making it a more future-proof choice for security-conscious applications.

  • jsonwebtoken:

    The jsonwebtoken library supports a wide range of cryptographic algorithms for signing and verifying JWTs, including HMAC (symmetric) and RSA/ECDSA (asymmetric) algorithms. However, it relies on the underlying Node.js crypto module for algorithm implementation, and some advanced features (e.g., custom algorithms) may require additional configuration.

Token Encryption

  • jose:

    The jose library fully supports both JWT signing (JWS) and encryption (JWE), making it a more versatile choice for applications that require secure token transmission. Its built-in support for JWE allows developers to easily encrypt tokens, providing an additional layer of security for sensitive data.

  • jsonwebtoken:

    The jsonwebtoken library does not natively support JWT encryption (JWE - JSON Web Encryption); it focuses primarily on signing and verifying tokens (JWS - JSON Web Signature). For encryption, developers would need to use additional libraries or implement custom solutions, which can add complexity to the application.

Ease of Use: Code Examples

  • jose:

    Creating and verifying JWTs with jose

    const { jwtVerify, sign } = require('jose');
    const secret = new TextEncoder().encode('your-256-bit-secret');
    const token = await sign({ userId: 123 }, secret, { alg: 'HS256', expiresIn: '1h' });
    console.log('JWT:', token);
    const { payload } = await jwtVerify(token, secret);
    console.log('Decoded JWT:', payload);
    
  • jsonwebtoken:

    Creating and verifying JWTs with jsonwebtoken

    const jwt = require('jsonwebtoken');
    const secret = 'your-256-bit-secret';
    const token = jwt.sign({ userId: 123 }, secret, { algorithm: 'HS256', expiresIn: '1h' });
    console.log('JWT:', token);
    const decoded = jwt.verify(token, secret);
    console.log('Decoded JWT:', decoded);
    

How to Choose: jose vs jsonwebtoken

  • jose:

    Choose jose if you require a modern, standards-compliant library that supports a wide range of JOSE features, including JWT, JWS, JWE, and JWK. It is ideal for applications that need advanced cryptographic features, modular design, and a focus on security and performance.

  • jsonwebtoken:

    Choose jsonwebtoken if you need a well-established, feature-rich library with extensive documentation and community support. It is suitable for most applications requiring JWT creation, verification, and decoding, with support for multiple signing algorithms and customizable options.

README for jose

jose

jose is a JavaScript module for JSON Object Signing and Encryption, providing support for JSON Web Tokens (JWT), JSON Web Signature (JWS), JSON Web Encryption (JWE), JSON Web Key (JWK), JSON Web Key Set (JWKS), and more. The module is designed to work across various Web-interoperable runtimes including Node.js, browsers, Cloudflare Workers, Deno, Bun, and others.

Sponsor

Auth0 by Okta

If you want to quickly add JWT authentication to JavaScript apps, feel free to check out Auth0's JavaScript SDK and free plan. Create an Auth0 account; it's free!

💗 Help the project

Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.

Dependencies: 0

jose has no dependencies and it exports tree-shakeable ESM1.

Documentation

jose is distributed via npmjs.com, jsr.io, jsdelivr.com, and github.com.

example ESM import1

import * as jose from 'jose'

JSON Web Tokens (JWT)

The jose module supports JSON Web Tokens (JWT) and provides functionality for signing and verifying tokens, as well as their JWT Claims Set validation.

Encrypted JSON Web Tokens

The jose module supports encrypted JSON Web Tokens and provides functionality for encrypting and decrypting tokens, as well as their JWT Claims Set validation.

Key Utilities

The jose module supports importing, exporting, and generating keys and secrets in various formats, including PEM formats like SPKI, X.509 certificate, and PKCS #8, as well as JSON Web Key (JWK).

JSON Web Signature (JWS)

The jose module supports signing and verification of JWS messages with arbitrary payloads in Compact, Flattened JSON, and General JSON serialization syntaxes.

JSON Web Encryption (JWE)

The jose module supports encryption and decryption of JWE messages with arbitrary plaintext in Compact, Flattened JSON, and General JSON serialization syntaxes.

Other

The following are additional features and utilities provided by the jose module:

Supported Runtimes

The jose module is compatible with JavaScript runtimes that support the utilized Web API globals and standard built-in objects or are Node.js.

The following runtimes are supported (this is not an exhaustive list):

Please note that certain algorithms may not be available depending on the runtime used. You can find a list of available algorithms for each runtime in the specific issue links provided above.

Supported Versions

VersionSecurity Fixes 🔑Other Bug Fixes 🐞New Features ⭐Runtime and Module type
v6.xSecurity PolicyUniversal2 ESM1
v5.xSecurity PolicyUniversal2 CJS + ESM
v4.xSecurity PolicyUniversal2 CJS + ESM
v2.xSecurity PolicyNode.js CJS

Specifications

Details

The algorithm implementations in jose have been tested using test vectors from their respective specifications as well as RFC7520.

Footnotes

  1. CJS style let jose = require('jose') is possible in Node.js versions where the require(esm) feature is enabled by default (^20.19.0 || ^22.12.0 || >= 23.0.0). 2 3

  2. Assumes runtime support of WebCryptoAPI and Fetch API 2 3