JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6236
  • Score
    100M100P100Q138011F
  • License Apache-2.0

Provides a middleware function for wrapping a window.Request object with d2l authentication for use with d2l-fetch

Package Exports

  • d2l-fetch-auth

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (d2l-fetch-auth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

d2l-fetch-auth

Provides a middleware function for wrapping a window.Request object with d2l authentication for use with d2l-fetch.

Setup

yarn install

Build

npm run build

Usage

Reference the script in your html after your reference to d2l-fetch (see here for details on d2l-fetch):

Install d2l-fetch-auth via npm:

npm install Brightspace/d2l-fetch-auth
<script type="module">
import auth from 'd2l-fetch-auth/dist/d2l-fetch-auth.js';
</script>

Alternatively, if you are making requests from within the context of an iFramed Free Range Application (iFRA), reference the framed script:

<script type="module">
import auth from 'd2l-fetch-auth/dist/d2l-fetch-auth.js';
</script>

This will import the auth middleware function.

Auth

Install the auth middleware to d2lfetch via the use function and then start making your requests.

d2lfetch.use({name: 'auth', fn: auth});

d2lfetch.fetch(new Request('http://example.com/api/entity/1'))
    .then(function(response) {
        // do something with the response
    });

Browser compatibility

d2l-fetch-auth makes use of a javascript feature that is not yet fully supported across all modern browsers: Promises. If you need to support browsers that do not yet implement this feature you will need to include polyfills for this functionality.

We recommend:

Publishing

The application will automatically increment the minor build version and publish a release version to the Brightspace CDN after merge to the master branch is complete. If you wish to increment the patch or major version instead please add [increment patch] or [increment major] to the notes inside your merge message.