fastify-txstate 3.6.1 → 3.6.3

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.
@@ -12,6 +12,8 @@ const issuerKeys = new Map();
12
12
  const issuerConfig = new Map();
13
13
  const trustedClients = new Set();
14
14
  const uaCookieName = process.env.UA_COOKIE_NAME ?? (0, crypto_1.randomBytes)(16).toString('hex');
15
+ const uaCookieNameRegex = new RegExp(`${uaCookieName}=([^;]+)`);
16
+ const uaServiceUrl = (0, txstate_utils_1.isNotBlank)(process.env.PUBLIC_URL) ? process.env.PUBLIC_URL + (process.env.PUBLIC_URL.endsWith('/') ? '' : '/') + '.uaService' : undefined;
15
17
  const tokenCache = new txstate_utils_1.Cache(async (token, req) => {
16
18
  const claims = (0, jose_1.decodeJwt)(token);
17
19
  let verifyKey;
@@ -69,9 +71,7 @@ function processIssuerConfig(config) {
69
71
  if (config.iss === 'unified-auth') {
70
72
  const validateUrl = (0, txstate_utils_1.isNotBlank)(config.validateUrl)
71
73
  ? new URL(config.validateUrl, config.url)
72
- : (0, txstate_utils_1.isNotBlank)(process.env.UA_URL)
73
- ? new URL(process.env.UA_URL + '/validateToken')
74
- : new URL('validateToken', config.url);
74
+ : new URL('validateToken', config.url);
75
75
  const logoutUrl = (0, txstate_utils_1.isNotBlank)(config.logoutUrl)
76
76
  ? new URL(config.logoutUrl, config.url)
77
77
  : (0, txstate_utils_1.isNotBlank)(process.env.UA_URL)
@@ -113,7 +113,7 @@ function tokenFromReq(req) {
113
113
  const m = req?.headers.authorization?.match(/^bearer (.*)$/i);
114
114
  if (m != null)
115
115
  return m[1];
116
- const m2 = req?.headers.cookie?.match(new RegExp(`${uaCookieName}=([^;]+)`));
116
+ const m2 = req?.headers.cookie?.match(uaCookieNameRegex);
117
117
  if (m2 != null)
118
118
  return m2[1];
119
119
  }
@@ -168,7 +168,7 @@ async function requireCookieAuth(req, res) {
168
168
  if ((0, txstate_utils_1.isBlank)(req.auth?.username)) {
169
169
  const loginUrl = new URL(process.env.UA_URL + '/login');
170
170
  loginUrl.searchParams.set('clientId', process.env.UA_CLIENTID);
171
- loginUrl.searchParams.set('returnUrl', (0, txstate_utils_1.isNotBlank)(process.env.PUBLIC_URL) ? new URL(process.env.PUBLIC_URL + '/.uaService').toString() : new URL('/.uaService', req.url).toString());
171
+ loginUrl.searchParams.set('returnUrl', uaServiceUrl ?? new URL('/.uaService', req.url).toString());
172
172
  loginUrl.searchParams.set('requestedUrl', req.originalUrl);
173
173
  void res.redirect(loginUrl.toString());
174
174
  return true;
@@ -233,7 +233,8 @@ function registerUaCookieRoutes(app) {
233
233
  }, async (req, res) => {
234
234
  const loginUrl = new URL(process.env.UA_URL + '/login');
235
235
  loginUrl.searchParams.set('clientId', process.env.UA_CLIENTID);
236
- loginUrl.searchParams.set('returnUrl', new URL('.uaService', process.env.PUBLIC_URL || new URL(req.url, req.protocol + '://' + req.hostname)).toString());
236
+ const returnUrl = uaServiceUrl ?? new URL('.uaService', req.protocol + '://' + req.hostname).toString();
237
+ loginUrl.searchParams.set('returnUrl', returnUrl);
237
238
  if (req.query.requestedUrl)
238
239
  loginUrl.searchParams.set('requestedUrl', req.query.requestedUrl);
239
240
  return res.redirect(loginUrl.toString());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-txstate",
3
- "version": "3.6.1",
3
+ "version": "3.6.3",
4
4
  "description": "A small wrapper for fastify providing a set of common conventions & utility functions we use.",
5
5
  "exports": {
6
6
  ".": {