Brightspace Auth Token Provisioning

9.0.1 · active · verified Wed Apr 22

The `brightspace-auth-provisioning` library facilitates the creation and assertion of access tokens against a Brightspace authentication service. It abstracts the complexities of token generation, allowing developers to provision tokens with specific claims such as scopes, tenant IDs, user IDs, impersonator IDs, and Caliper FSIDs. The current stable version is `9.0.1`, which requires Node.js version `20.x` or higher. The package sees active development with major versions released periodically (e.g., v7, v8, v9) and more frequent patch and minor releases. Its key differentiator is its tight integration with the Brightspace authentication ecosystem, providing a specific API for generating tokens that adhere to Brightspace's assertion requirements, including a flexible `keyLookup` mechanism for signing keys and support for caching mechanisms.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate `AuthTokenProvisioner`, provide a `keyLookup` function returning a `KeyObject`, and then use it to provision an access token with specified claims.

import { AuthTokenProvisioner } from 'brightspace-auth-provisioning';
import { KeyObject, generateKeyPairSync } from 'node:crypto';

async function provisionExampleToken() {
  // Generate a dummy key pair for demonstration purposes
  // In a real application, you would load this securely
  const { privateKey } = generateKeyPairSync('ec', {
    namedCurve: 'P-256',
    publicKeyEncoding: { type: 'spki', format: 'pem' },
    privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
  });

  const provisioner = new AuthTokenProvisioner({
    issuer: 'ece083bc-e6ac-11e4-8e1b-54ee750fffa4', // Replace with your service's issuer GUID
    keyLookup: async () => {
      return {
        kid: '0a9e68f6-e6ad-11e4-8ab6-54ee750fffa4', // Replace with your key ID
        key: privateKey, // Must be a node:crypto KeyObject
        alg: 'ES256'
      };
    }
  });

  try {
    const token = await provisioner.provisionToken({
      user: '32647',
      impersonator: '30882',
      tenant: '5492ff8a-e6ad-11e4-84d6-54ee750fffa4',
      scopes: ['updates:feed-items:read', 'core:*:*'],
      fsid: 'eyJhbGciOiJIUzI1Ni...' // Optional Caliper FSID
    });
    console.log('Successfully provisioned token:', token);
    return token;
  } catch (error) {
    console.error('Error provisioning token:', error);
    throw error;
  }
}

provisionExampleToken();

view raw JSON →