fastify-txstate 3.6.2 → 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.
- package/lib/unified-auth.js +4 -2
- package/package.json +1 -1
package/lib/unified-auth.js
CHANGED
|
@@ -13,6 +13,7 @@ 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
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;
|
|
16
17
|
const tokenCache = new txstate_utils_1.Cache(async (token, req) => {
|
|
17
18
|
const claims = (0, jose_1.decodeJwt)(token);
|
|
18
19
|
let verifyKey;
|
|
@@ -167,7 +168,7 @@ async function requireCookieAuth(req, res) {
|
|
|
167
168
|
if ((0, txstate_utils_1.isBlank)(req.auth?.username)) {
|
|
168
169
|
const loginUrl = new URL(process.env.UA_URL + '/login');
|
|
169
170
|
loginUrl.searchParams.set('clientId', process.env.UA_CLIENTID);
|
|
170
|
-
loginUrl.searchParams.set('returnUrl',
|
|
171
|
+
loginUrl.searchParams.set('returnUrl', uaServiceUrl ?? new URL('/.uaService', req.url).toString());
|
|
171
172
|
loginUrl.searchParams.set('requestedUrl', req.originalUrl);
|
|
172
173
|
void res.redirect(loginUrl.toString());
|
|
173
174
|
return true;
|
|
@@ -232,7 +233,8 @@ function registerUaCookieRoutes(app) {
|
|
|
232
233
|
}, async (req, res) => {
|
|
233
234
|
const loginUrl = new URL(process.env.UA_URL + '/login');
|
|
234
235
|
loginUrl.searchParams.set('clientId', process.env.UA_CLIENTID);
|
|
235
|
-
|
|
236
|
+
const returnUrl = uaServiceUrl ?? new URL('.uaService', req.protocol + '://' + req.hostname).toString();
|
|
237
|
+
loginUrl.searchParams.set('returnUrl', returnUrl);
|
|
236
238
|
if (req.query.requestedUrl)
|
|
237
239
|
loginUrl.searchParams.set('requestedUrl', req.query.requestedUrl);
|
|
238
240
|
return res.redirect(loginUrl.toString());
|