qr-code.js

QRCode.js License Management

Introduction

QRCode.js uses a license key system to enable premium features. Activation involves validating a JSON Web Token (JWT) which contains details about your license grant. This validation happens client-side (in the browser) or server-side (in Node.js) against a public key embedded in the library.

Premium Features

A valid license is required to use the following premium features:

Free Usage

QRCode.js can be used for free without a license key or premium features. In its free mode, it allows you to create full-featured, styled QR codes without premium border features or built-in scan validation. No other restrictions are applied, meaning you can still customize colors, sizes, shapes, and other styling options available in the base library.

Border Limitations in Free Version

When using the basic border features in the free version, the library will automatically add “QR-Platform” branding text in the bottom border. This branded text cannot be removed or modified without a valid license. With a premium license, you gain full control over border text and can use borders without any branding.

Core Concepts

Free vs. Premium Features

Activation Timing

Initialization

Persistence

Browser Environment

Node.js Environment

Token Retrieval and Reuse

Activation Methods

Using a License Key (QRCodeJs.license())

Using a Pre-fetched Token (QRCodeJs.token())

Domain Validation (Browser Only)

Configuration

Setting License URL

Custom License Fetcher

Checking License Status

Getting License Details

Initializing License Manager

Error Handling

Node.js Usage

Key Differences from Browser

Node.js Examples

Using license() with async/await

async function activateLicenseNode() {
  try {
    QRCodeJs.setLicenseUrl('https://your-license-api.com/get-token');
    const result = await QRCodeJs.license('YOUR-NODE-LICENSE-KEY');
    if (result.isValid) {
      console.log('Node: License activated!', result.license.plan);
      const qrInstance = new QRCodeJs({
        data: 'https://example.com',
        borderOptions: { inner: true }
      });
    } else {
      console.error('Node: License activation failed.');
    }
  } catch (error) {
    console.error('Node: Error:', error);
  }
}

Using token() with async/await

async function activateWithTokenNode(token) {
  try {
    const result = await QRCodeJs.token(token);
    if (result.isValid) {
      console.log('Node: License activated!', result.license.plan);
      const qrInstance = new QRCodeJs({
        data: 'https://example.com',
        borderOptions: { outer: true }
      });
    } else {
      console.error('Node: Token invalid or expired.');
    }
  } catch (error) {
    console.error('Node: Error:', error);
  }
}

Backend Implementation Guide

Endpoint

Request Format

{
  "licenseKey": "THE_USER_PROVIDED_KEY"
}

Processing Steps

  1. Extract and validate licenseKey
  2. Generate a JWT with this payload:
     {
       "sub": "license-12345",
       "client": "acme-corp",
       "plan": "enterprise",
       "email": "admin@acme.com",
       "domains": ["acme.com", "acme.org"],
       "iat": 1712668800,
       "exp": 1744204800
     }
    
  3. Sign with your private key

Response Format

Security Best Practices

API Reference

Static Methods

license()

token()

setLicenseUrl()

configureLicenseFetcher()

getLicenseDetails()

initializeIfNeeded()

Interfaces

ValidationResult

interface ValidationResult {
  isValid: boolean;
  token: string | null;
  license: DecodedLicenseToken | null;
  reason?: LicenseReasonCode;
}

DecodedLicenseToken

interface DecodedLicenseToken {
  sub: string;
  client: string;
  plan: string;
  email?: string;
  domains?: string[];
  iat: number;
  exp: number;
}

Troubleshooting and FAQ

Activation Issues

Common Questions

Can I use QRCode.js for free without a license?

Yes, QRCode.js can be used for free without a license key. This allows you to create full-featured, styled QR codes without premium features like advanced borders or built-in scan validation. There are no other restrictions in free mode.

What happens if I use border features in the free version?

When using border features without a license, the library will automatically add “QR-Platform” branding text in the bottom border of your QR code. This branding cannot be removed or customized in the free version. A premium license removes this restriction, allowing you to create custom border text or remove text entirely.

Can I modify or remove the QR-Platform branding in the free version?

No, the QR-Platform branding in the bottom border is automatically added when using border features in the free version and cannot be modified or removed. This is a limitation of the free version. Purchasing a license allows you to remove the branding and fully customize your border text.

Do I need to activate the license on every page load?

What happens if the license expires?

getLicenseDetails() returns null; you’ll need to renew with license() or token().

Can I use this offline?

token() works offline with a valid JWT; license() requires internet connection.

How can I check which premium features are enabled?

Check getLicenseDetails().plan to determine which features should be available.

Why are premium features not working?

Ensure activation was completed before QRCode instances were created. Check for errors in the console or network requests. If using a token, ensure it is valid and not expired. If you are still having issues, please contact us for support.


See Also