Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

azure-ad-verify-token

justinlettau21.5kMIT3.0.3TypeScript support: included

Verify JWT issued by Azure Active Directory B2C.

azure, ad, b2c, jwt, verify, token

readme

NPM Version CI Codecov

Azure AD Verify Token

Verify JWT issued by Azure Active Directory B2C.

Table of Contents

Features

  • 🎉 Verify JWT issued by Azure Active Directory B2C.
  • 🚀 Automatically use the rotated public keys from Azure.
  • 💪 Written in TypeScript.
  • ♻️ Configurable cache for public keys.

Installation

npm install azure-ad-verify-token --save

Usage

Verify

import { verify, VerifyOptions } from 'azure-ad-verify-token';

const options: VerifyOptions = {
  jwksUri:
    'https://contoso.b2clogin.com/contoso.onmicrosoft.com/discovery/v2.0/keys?p=b2c_1_signupsignin1',
  issuer:
    'https://contoso.b2clogin.com/3285c484-dce5-4abb-a341-bbe4f2bc8554/v2.0/',
  audience: '99d1275c-e805-483f-b832-600f8130829c',
};

verify(token, options)
  .then((decoded) => {
    // verified and decoded token
    console.log(decoded);
  })
  .catch((error) => {
    // invalid token
    console.error(error);
  });

Verify options:

Property Type Description
jwksUri string jwk_uri value obtained from B2C policy metadata endpoint.
issuer string issuer value obtained from B2C policy metadata endpoint.
audience string Application ID of the application accessing the tenant.

Example metadata endpoints:

Configuration

import { setConfig } from 'azure-ad-verify-token';

setConfig({
  cacheLifetime: 12 * (60 * 60 * 1000), // 12 hours
});

Configuration options:

Property Type Description Default
cacheLifetime number Number of milliseconds to cache public keys. 1 hour

References

Development

npm install
npm run build

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.0.3 (2023-07-28)

Bug Fixes

3.0.2 (2023-06-25)

Bug Fixes

3.0.1 (2023-02-23)

3.0.0 (2023-01-26)

⚠ BREAKING CHANGES

  • Major version bump for jsonwebtoken and node-fetch

Features

2.0.1 (2022-07-16)

Bug Fixes

2.0.0 (2021-10-29)

⚠ BREAKING CHANGES

  • This package is now pure ESM

Features

1.1.2 (2021-08-27)

Bug Fixes

  • throw error when kid is not present (#29) (a968886)

1.1.1 (2020-11-28)

1.1.0 (2020-03-28)

Features

Bug Fixes

1.0.1 (2020-03-22)

Bug Fixes

  • export config interface (f43c49b)

1.0.0 (2020-03-22)