Skip to content

Commit

Permalink
Drop jsonwebtoken and jwks-rsa in favor of jose (#37)
Browse files Browse the repository at this point in the history
* chore: depedencies update and TS support

* feat: Authentic rewrite to use Jose

* infra: build CJS and ESM module

* fix: validate token without `Bearer`

* fix: throw Boom errors for incorrect ISS

* fix: show OIDC http request error message

* test: added tests using Jest

* test: further tests

* fix: validate error instance instead of assertion

* docs: update README references

* ci: adding changeset release

* test: add test for missing required claim

* docs: changelog

* fix: Removing the authentic export default option

BREAKING CHANGE: Authentic doesn't have an default export anymore, services using this
newer version will need to import `authentic` from authentic

* text: fixed named import on test

* fix: fix OIDC fetching for issuers with URLs with path

* fix: make "aud" claim optional

* fix: stop requiring any claims

* feat: allow JWK URLs with custom ports

* docs: update CHANGELOG.md
  • Loading branch information
lucasadrianof authored Sep 6, 2023
1 parent 908f3db commit e0ab92a
Show file tree
Hide file tree
Showing 29 changed files with 16,068 additions and 5,411 deletions.
15 changes: 15 additions & 0 deletions .changeset/curly-bottles-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@articulate/authentic": major
---

Typescript refactor and replace `jsonwebtoken` and `jwks-rsa` in favor of `jose`

The biggest change on this version is the replacement of [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) and [jwks-rsa](https://github.com/auth0/node-jwks-rsa) in favor of [jose](https://github.com/panva/jose). jose exports the same features the other two libraries offer, without adding the extra dependencies previously required (it has zero dependencies!). This change significantly decreases `@authentic` final bundle size, allowing it to also be used in Lambdas.

Also, this new version doesn't export `authentic` as a default export anymore, apps using this new version will to import/require `{ authentic } from "@articulate/authentic"` instead.

Before upgrading make sure your app uses the new expected `jwks` and `verify` options (which differ from the old ones).

### Dual Export of ESM and CJS Bundles

Starting with this new version, Authentic started exporting both an ECMAScript Module (ESM) bundle and a CommonJS (CJS) bundle. This means that applications utilizing either of these architectures can now choose the bundle that best suits their specific use case.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.changeset
.git*
coverage
dist
node_modules
28 changes: 16 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
module.exports = {
'env': {
'es2017': true,
'mocha': true,
'node': true
env: {
es2020: true,
node: true
},
'extends': 'eslint:recommended',
'parserOptions': {
'sourceType': 'module'
},
'rules': {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint'
],
root: true,
rules: {
'eol-last': ['error', 'always'],
'indent': ['error', 2, { 'SwitchCase': 1 }],
indent: ['error', 2, { 'SwitchCase': 1 }],
'linebreak-style': ['error', 'unix'],
'no-console': 'off',
'no-trailing-spaces': 'error',
'quotes': ['error', 'single', { 'allowTemplateLiterals': true }],
'semi': ['error', 'never']
quotes: ['error', 'single', { 'allowTemplateLiterals': true }],
semi: ['error', 'never']
}
}
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.log
coverage
.DS_Store
/node_modules
/.nyc_output
.nyc_output
coverage
dist
node_modules
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# @articulate/authentic
[![@articulate/authentic](https://img.shields.io/npm/v/@articulate/authentic.svg)](https://www.npmjs.com/package/@articulate/authentic)
[![Build Status](https://travis-ci.org/articulate/authentic.svg?branch=master)](https://travis-ci.org/articulate/authentic)
[![Coverage Status](https://coveralls.io/repos/github/articulate/authentic/badge.svg?branch=master)](https://coveralls.io/github/articulate/authentic?branch=master)

Proper validation of JWT's against JWK's.
Expand Down Expand Up @@ -42,16 +41,17 @@ const handler = req =>

`authentic` accepts a JSON object with the following options:

* `jwks` Object: options to forward to [`node-jwks-rsa`](https://github.com/auth0/node-jwks-rsa) with the following defaults:
* `jwks` Object: options to forward to `jose.createRemoteJWKSet` from [`jose`](https://github.com/panva/jose/blob/main/docs/interfaces/jwks_remote.RemoteJWKSetOptions.md) with the following defaults:

| option | default |
| ----------- | ------- |
| `cache` | `true` |
| `rateLimit` | `true` |
| `timeoutDuration` | `5000` (5 seconds) |
| `cooldownDuration` | `30000` (30 seconds) |
| `cacheMaxAge` | `60000` (10 minutes) |

* `verify` Object: options to forward to `jwt.verify` from [`jsonwebtoken`](https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback)
* `verify` Object: options to forward to `jose.jwtVerify` from [`jose`](https://github.com/panva/jose/blob/main/docs/interfaces/jwt_verify.JWTVerifyOptions.md)
* `issWhitelist` Array: list of trusted OIDC issuers
* `claimsInError` Array: list of jwt payload claims to receive as the `data` propery of the error when verification fails. When a list is not provided a `data` property will not be added to the error.
* `claimsInError` Array: list of jwt payload claims to receive as the `data` property of the error when verification fails. When a list is not provided a `data` property will not be added to the error.

## Contributing

Expand Down
51 changes: 0 additions & 51 deletions index.d.ts

This file was deleted.

109 changes: 0 additions & 109 deletions index.js

This file was deleted.

5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}
7 changes: 0 additions & 7 deletions lib/errors.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/helpers.js

This file was deleted.

42 changes: 0 additions & 42 deletions lib/http.js

This file was deleted.

Loading

0 comments on commit e0ab92a

Please sign in to comment.