Registry / auth-security / d2l-fetch-auth

d2l-fetch-auth

JSON →
library1.9.1jsnpmunverified

Middleware function for wrapping a window.Request object with Brightspace (D2L) authentication for use with d2l-fetch. Current stable version is 1.9.1. This package is specifically designed for D2L/Brightspace ecosystems, providing seamless integration with their authentication system for fetch requests. It offers two variants: a standard auth middleware and a framed version for iFramed Free Range Applications (iFRA). Release cadence follows semantic-release, triggered by `fix:` and `feat:` prefixed commits. Key differentiators: handles D2L-specific auth tokens and headers, works with both top-level and iframed contexts.

npm install d2l-fetch-auth
INSTALL
IMPORT
SIG · D2L-FETCH-AUTH
D
d2l-fetch-auth
auth-securityjavascriptv1.9.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

auth (default)
✓ import auth from 'd2l-fetch-auth/d2l-fetch-auth.js';
✗ import { auth } from 'd2l-fetch-auth';
The module exports a default function. Named import will fail. For iFRAs, use 'd2l-fetch-auth/d2l-fetch-auth-framed.js'.
auth (default) for iFRA
✓ import auth from 'd2l-fetch-auth/d2l-fetch-auth-framed.js';
✗ import auth from 'd2l-fetch-auth/d2l-fetch-auth.js';
If your app runs in an iframed context (iFRA), you must use the framed version.
auth (CommonJS)
✓ const auth = require('d2l-fetch-auth/d2l-fetch-auth.js');
CommonJS require is available for older environments; but ESM is recommended.

Shows how to import and use the auth middleware with d2l-fetch to make authenticated requests.

// Ensure d2l-fetch is loaded first import d2lfetch from 'd2l-fetch'; import auth from 'd2l-fetch-auth/d2l-fetch-auth.js'; d2lfetch.use({name: 'auth', fn: auth}); const response = await d2lfetch.fetch( new Request('https://api.example.com/entity/1') ); const data = await response.json(); console.log(data);
Debug
Known issues
gotchaUsing wrong import path for iframed vs non-iframed context will cause authentication failures in iFRAs.
fix
If your app runs in an iframe, use `'d2l-fetch-auth/d2l-fetch-auth-framed.js'`.
affects: >=1.0.0
gotchaThe auth middleware must be used via `d2lfetch.use()`; importing alone does not activate it.
fix
Call `d2lfetch.use({name: 'auth', fn: auth})` after importing.
affects: >=1.0.0
deprecatedOlder versions may not support ES module imports; check your d2l-fetch version compatibility.
fix
Upgrade to version 1.0.0 or later.
affects: <1.0.0
gotchaIf d2l-fetch is not initialized or loaded, the middleware will not function.
fix
Ensure d2l-fetch is installed and imported before using d2l-fetch-auth.
affects: >=1.0.0
breakingVersion 1.0.0 changed the import path from legacy scripts to ES modules. Old script tags may break.
fix
Update HTML script tags to use `type="module"` and the new import paths.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught SyntaxError: The requested module 'd2l-fetch-auth/d2l-fetch-auth.js' does not provide an export named 'auth'
Trying named import `{ auth }` instead of default import.
fix
Use `import auth from 'd2l-fetch-auth/d2l-fetch-auth.js';`
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html"
Import path point to a directory instead of the .js file, or the server is misconfigured.
fix
Use the full path ending with '.js': `import auth from 'd2l-fetch-auth/d2l-fetch-auth.js';`
TypeError: Cannot read properties of undefined (reading 'use')
d2l-fetch is not imported or initialized before calling `d2lfetch.use`.
fix
Import d2l-fetch first: `import d2lfetch from 'd2l-fetch';`
401 Unauthorized when making requests with d2l-fetch
Auth middleware not installed or using wrong variant (non-framed vs framed).
fix
Call `d2lfetch.use({name: 'auth', fn: auth});` after importing the correct auth middleware for your context.
Upgrade
Version history
1.9.1latest on npm
Audit
Dependencies
d2l-fetchrequiredThis middleware is designed to be used with d2l-fetch; it intercepts requests and adds authentication.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
d2l-fetch-auth — npm install d2l-fetch-auth · libregistry