1.0.4 • Published 4 months ago

azure-ad-jwt-verifier v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Azure AD Verifier

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-jwt-verifier --save

Usage

Verify

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

const options: VerifyOptions = {
  jwksUri: 'https://login.microsoftonline.com/common/discovery/keys',
  issuer: 'https://login.microsoftonline.com/<tenant_id>/v2.0',
  audience: '<client_id>',
};

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

Verify options:

PropertyTypeDescription
jwksUristringjwk_uri value obtained from B2C policy metadata endpoint.
issuerstringissuer value obtained from B2C policy metadata endpoint.
audiencestringApplication ID of the application accessing the tenant.

Example metadata endpoints:

Configuration

import { setConfig } from 'azure-ad-jwt-verifier';

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

Configuration options:

PropertyTypeDescriptionDefault
cacheLifetimenumberNumber of milliseconds to cache public keys.1 hour

References

Development

npm install
npm run build
1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago