# brightspace-auth-token

> Helper for interacting with an incoming Brightspace JWT

Latest version **10.0.0** (published 2026-06-24) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install brightspace-auth-token
pnpm add brightspace-auth-token
yarn add brightspace-auth-token
bun add brightspace-auth-token
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; has provenance.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 10.0.0 |
| Published | 2026-06-24 |
| First published | 2016-01-06 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=20.x |
| Dependencies | 0 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | D2L Corporation |
| Maintainers | d2l-travis-deploy |

## Links

- npm: https://www.npmjs.com/package/brightspace-auth-token
- Repository: https://github.com/Brightspace/node-auth
- Homepage: https://github.com/Brightspace/node-auth#readme
- Issues: https://github.com/Brightspace/node-auth/issues
- npm.io page: https://npm.io/package/brightspace-auth-token

## Recent versions

- 10.0.0 (latest) — 2026-06-24
- 9.0.1 — 2025-05-07
- 8.2.1 — 2022-05-12
- 8.2.0 — 2022-03-24
- 8.1.0 — 2021-08-24
- 8.0.0 — 2020-05-04
- 7.0.1 — 2020-05-01
- 7.0.0 — 2019-05-15
- 6.0.2 — 2018-03-05
- 6.0.1 — 2018-03-01
- 6.0.0 — 2018-01-25
- 3.2.0 — 2017-02-07
- 3.1.1 — 2016-01-06

## README

# brightspace-auth-token

## Usage

```js
import AuthToken from 'brightspace-auth-token';

// See brightspace-auth-validation to do this for you!
function authorizeRequest(req) {
	const signature = req.headers.authorization.match(/Bearer (.+)/)[1];
	const payload = parseAndValidateSignature(signature);

	return new AuthToken(payload, signature);
}

require('http')
	.createServer((req, res) => {
		const token = authorizeRequest(req);

		if (!token.hasScope('random', 'greetings', 'read')) {
			res.statusCode = 403;
			res.end('You don\'t have sufficient scope!\n');
			return;
		}

		let msg;
		if (token.isUserContext()) {
			msg = 'Hello user!\n';
		} else if (token.isTenantContext()) {
			msg = 'Hello service, acting at the tenant level!\n';
		} else if (token.isGlobalContext()) {
			msg = 'Hello service, maintaining all of our systems!\n';
		}

		res.statusCode = 200;
		res.end(msg);
	})
	.listen(3000);

```

### API

---

#### `new AuthToken(Object decodedPayload, String source)` -> `AuthToken`

_decodedPayload_ should be an already verified and parsed JWT body. _source_
should be the signature from which the payload was retrieved.

---

#### `.user` -> `String|Undefined`

The identifier for the user this token belongs to. Not present outside of user
context.

---

#### `.tenant` -> `String|Undefined`

The tenant UUID this token belongs to. Not present outside of user and tenant
contexts.

---

#### `.actualUser` -> `String|Undefined`

The identifier for the acting user. For convenience, this will always be the
same as `user` except in the case of impersonation. Not present outside of
user context.

---

#### `.azp` -> `String|Undefined`

The identifier for the party to whom this token was issued. If present it will contain
the OAuth 2.0 Client ID of the party. The identifier is a case-sensitive string which
may be a URI value.

---

#### `.isGlobalContext()` -> `Boolean`

___

#### `.isTenantContext()` -> `Boolean`

---

#### `.isUserContext()` -> `Boolean`

---

#### `.isImpersonating()` -> `Boolean`

---

#### `.context` -> `String`

___

#### `.hasScope(String group, String resource, String permission)` -> `Boolean`

---

#### `.scope` -> `Map`

---

#### `.cacheKey` -> `String`

A normalized string which could be used as part of cache keys when caching
resources.

---

#### `.source` -> `String`

The source signature provider when creating the token.

---
_Source: https://npm.io/package/brightspace-auth-token · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
