@auth0/auth0-express 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -251,7 +251,7 @@ Express still produces the final response. Its built-in error handler writes the
251
251
  - Run your app with `NODE_ENV=production` in any deployed environment, and/or
252
252
  - Mount your own [Express error-handling middleware](https://expressjs.com/en/guide/error-handling.html) after the Auth0 router. Read `error.cause` there if you want to log the original failure.
253
253
 
254
- The back-channel logout route is different: it is called server-to-server by Auth0, not by a browser, so the SDK owns its response directly and always replies with the status codes required by the [OpenID Connect Back-Channel Logout](https://openid.net/specs/openid-connect-backchannel-1_0.html) spec (a success status, which the SDK returns as `204` and the spec also allows as `200`, or `400` on failure) without internal detail in the body. It does **not** flow through your error-handling middleware. If you need to log or customize back-channel logout failures, mount your own route and call `req.auth0.client.handleBackchannelLogout(logoutToken)` directly.
254
+ The back-channel logout route is different: it is called server-to-server by Auth0, not by a browser, so the SDK owns its response directly and always replies with the status codes required by the [OpenID Connect Back-Channel Logout](https://openid.net/specs/openid-connect-backchannel-1_0.html) spec (a success status, which the SDK returns as `204` and the spec also allows as `200`, or `400` on failure) without internal detail in the body. The route reads the `application/x-www-form-urlencoded` body that Auth0 sends itself, so you do not need to mount a body parser for it, and a body that a parser of yours has already read is left as it is. A parser that you mounted before the Auth0 router can still refuse a request first, and that goes to your error handler. Apart from that, the route does **not** flow through your error-handling middleware. If you need to log or customize back-channel logout failures, mount your own route and call `req.auth0.client.handleBackchannelLogout(logoutToken)` directly. A route of your own does not get the body parsing, so mount `express.urlencoded({ extended: false })` on it.
255
255
 
256
256
  ## Feedback
257
257
 
@@ -1,3 +1,14 @@
1
- import { Request, Response } from 'express';
1
+ import { NextFunction, Request, Response } from 'express';
2
+ /**
3
+ * Reads the body of a back-channel logout request. Auth0 sends the `logout_token` as `application/x-www-form-urlencoded`
4
+ * (OpenID Connect Back-Channel Logout, section 2.5), and the router mounts no body parser for the app, so the route
5
+ * parses the form itself. A parser that the app mounted earlier has already read the body, and this one leaves it as it
6
+ * is. A body that cannot be read is answered as any other failure here, with a bare `400`.
7
+ */
8
+ export declare function parseBackchannelLogoutBody(req: Request, res: Response, next: NextFunction): void;
9
+ /**
10
+ * Passes the `logout_token` of a back-channel logout request to the client, and answers `204`. Any failure is answered
11
+ * with a bare `400`, and the returned promise never rejects.
12
+ */
2
13
  export declare function handleBackchannelLogout(req: Request, res: Response): Promise<void>;
3
14
  //# sourceMappingURL=backchannel-logout-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"backchannel-logout-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/backchannel-logout-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAcxF"}
1
+ {"version":3,"file":"backchannel-logout-handler.d.ts","sourceRoot":"","sources":["../../src/handlers/backchannel-logout-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAc,MAAM,SAAS,CAAC;AAItE;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAgBhG;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBxF"}
@@ -1,15 +1,46 @@
1
- export async function handleBackchannelLogout(req, res) {
2
- const logoutToken = req.body.logout_token;
3
- if (!logoutToken) {
4
- res.status(400).send('Missing `logout_token` in the request body.');
1
+ import { urlencoded } from 'express';
2
+ const parseForm = urlencoded({ extended: false });
3
+ /**
4
+ * Reads the body of a back-channel logout request. Auth0 sends the `logout_token` as `application/x-www-form-urlencoded`
5
+ * (OpenID Connect Back-Channel Logout, section 2.5), and the router mounts no body parser for the app, so the route
6
+ * parses the form itself. A parser that the app mounted earlier has already read the body, and this one leaves it as it
7
+ * is. A body that cannot be read is answered as any other failure here, with a bare `400`.
8
+ */
9
+ export function parseBackchannelLogoutBody(req, res, next) {
10
+ // A body that something else has already read cannot be read again. The body parser of Express 5 sees this, but the one
11
+ // of Express 4 only knows the bodies that it read itself, and it would refuse this one with an error.
12
+ if (req.readableEnded) {
13
+ next();
5
14
  return;
6
15
  }
16
+ parseForm(req, res, (error) => {
17
+ if (error) {
18
+ res.status(400).send();
19
+ return;
20
+ }
21
+ next();
22
+ });
23
+ }
24
+ /**
25
+ * Passes the `logout_token` of a back-channel logout request to the client, and answers `204`. Any failure is answered
26
+ * with a bare `400`, and the returned promise never rejects.
27
+ */
28
+ export async function handleBackchannelLogout(req, res) {
29
+ // Express 4 does not catch a promise that a handler rejects, and that ends the process, so every failure is answered
30
+ // here and the promise never rejects.
7
31
  try {
32
+ const logoutToken = req.body?.logout_token;
33
+ if (!logoutToken) {
34
+ res.status(400).send('Missing `logout_token` in the request body.');
35
+ return;
36
+ }
8
37
  await req.auth0.client.handleBackchannelLogout(logoutToken);
9
38
  res.status(204).send(null);
10
39
  }
11
40
  catch {
12
- res.status(400).send();
41
+ if (!res.headersSent) {
42
+ res.status(400).send();
43
+ }
13
44
  }
14
45
  }
15
46
  //# sourceMappingURL=backchannel-logout-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"backchannel-logout-handler.js","sourceRoot":"","sources":["../../src/handlers/backchannel-logout-handler.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,GAAY,EAAE,GAAa;IACvE,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC;IAE1C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QAC5D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"backchannel-logout-handler.js","sourceRoot":"","sources":["../../src/handlers/backchannel-logout-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtE,MAAM,SAAS,GAAG,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;IACxF,wHAAwH;IACxH,sGAAsG;IACtG,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,IAAI,EAAE,CAAC;QACP,OAAO;IACT,CAAC;IAED,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,KAAe,EAAE,EAAE;QACtC,IAAI,KAAK,EAAE,CAAC;YACV,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QAED,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,GAAY,EAAE,GAAa;IACvE,qHAAqH;IACrH,sCAAsC;IACtC,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC;QAE3C,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;YACpE,OAAO;QACT,CAAC;QAED,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QAC5D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC"}
package/dist/router.js CHANGED
@@ -4,7 +4,7 @@ import { createServerClientInstance } from './utils.js';
4
4
  import { handleLogin } from './handlers/login-handler.js';
5
5
  import { handleCallback } from './handlers/callback-handler.js';
6
6
  import { handleLogout } from './handlers/logout-handler.js';
7
- import { handleBackchannelLogout } from './handlers/backchannel-logout-handler.js';
7
+ import { handleBackchannelLogout, parseBackchannelLogoutBody } from './handlers/backchannel-logout-handler.js';
8
8
  import { runWithContext } from './store/request-context.js';
9
9
  import { getConfig } from './config.js';
10
10
  import './types/express.js';
@@ -69,7 +69,7 @@ export function createAuth0(opts = {}) {
69
69
  router.get(routes.login, (req, res, next) => handleLogin(req, res, options, next));
70
70
  router.get(routes.callback, (req, res, next) => handleCallback(req, res, options, next));
71
71
  router.get(routes.logout, (req, res, next) => handleLogout(req, res, options, next));
72
- router.post(routes.backchannelLogout, (req, res) => handleBackchannelLogout(req, res));
72
+ router.post(routes.backchannelLogout, parseBackchannelLogoutBody, (req, res) => handleBackchannelLogout(req, res));
73
73
  }
74
74
  return router;
75
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmC,MAAM,SAAS,CAAC;AA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OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QACzF,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QACrF,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,0BAA0B,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,uBAAuB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACrH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/auth0-express",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Auth0 Authentication SDK for Express Applications on JavaScript runtimes",
5
5
  "author": "Auth0",
6
6
  "license": "Apache-2.0",
@@ -14,6 +14,7 @@
14
14
  "clean": "rm -rf ./dist",
15
15
  "lint": "eslint \"./**/*.ts*\"",
16
16
  "test": "vitest run",
17
+ "test:express4": "vitest run --config vitest.express4.config.ts",
17
18
  "test:ci": "vitest --watch false --coverage"
18
19
  },
19
20
  "types": "./dist/index.d.ts",