Superagent D2L Session Authentication

2.0.1 · active · verified Wed Apr 22

superagent-d2l-session-auth is a JavaScript plugin designed to integrate D2L (Brightspace) session authentication with `superagent` HTTP requests. It acts as a `superagent` middleware, automatically adding the necessary D2L authentication headers to outbound requests by leveraging the `frau-jwt` library internally. The current stable version is 2.0.1, which includes a fix for `trustedHost` casing sensitivity. While specific release cadence is not explicitly stated, the project appears to be actively maintained by Brightspace, with updates addressing functionality and compatibility. Its primary differentiator is its specialized function within the Brightspace ecosystem, providing a streamlined way to handle D2L session-based authentication for applications using `superagent`, particularly within iframed contexts.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the `superagent-d2l-session-auth` plugin and attach it to a `superagent` request for D2L API interaction.

const request = require('superagent');
const auth = require('superagent-d2l-session-auth')({
    scope: '*:*:*',
    trustedHost: 'school.brightspace.com' // Replace with your D2L domain
});

// Example using a placeholder D2L API endpoint
request
    .get('https://school.brightspace.com/d2l/api/lp/1.5/users/whoami')
    .use(auth)
    .end(function(err, res) {
        if(err) {
           console.error('Failed to fetch user info: ' + err.status + ' ' + (err.response ? err.response.text : ''));
           return;
        }
        const user = res.body;
        console.log('Hello, ' + user.FirstName + ' ' + user.LastName);
    });

view raw JSON →