fastify-txstate 3.6.0 → 3.6.2
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.d.ts +0 -1
- package/lib/unified-auth.js +7 -9
- package/lib-esm/index.js +1 -0
- package/package.json +1 -1
package/lib/unified-auth.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export interface IssuerConfigRaw extends Omit<IssuerConfig, 'validateUrl' | 'log
|
|
|
4
4
|
validateUrl?: string;
|
|
5
5
|
logoutUrl?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const uaCookieName: string;
|
|
8
7
|
export declare function unifiedAuthenticate(req: FastifyRequest, options?: {
|
|
9
8
|
authenticateAll?: boolean;
|
|
10
9
|
exceptRoutes?: Set<string>;
|
package/lib/unified-auth.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uaCookieName = void 0;
|
|
4
3
|
exports.unifiedAuthenticate = unifiedAuthenticate;
|
|
5
4
|
exports.unifiedAuthenticateAll = unifiedAuthenticateAll;
|
|
6
5
|
exports.requireCookieAuth = requireCookieAuth;
|
|
@@ -12,7 +11,8 @@ let hasInit = false;
|
|
|
12
11
|
const issuerKeys = new Map();
|
|
13
12
|
const issuerConfig = new Map();
|
|
14
13
|
const trustedClients = new Set();
|
|
15
|
-
|
|
14
|
+
const uaCookieName = process.env.UA_COOKIE_NAME ?? (0, crypto_1.randomBytes)(16).toString('hex');
|
|
15
|
+
const uaCookieNameRegex = new RegExp(`${uaCookieName}=([^;]+)`);
|
|
16
16
|
const tokenCache = new txstate_utils_1.Cache(async (token, req) => {
|
|
17
17
|
const claims = (0, jose_1.decodeJwt)(token);
|
|
18
18
|
let verifyKey;
|
|
@@ -70,9 +70,7 @@ function processIssuerConfig(config) {
|
|
|
70
70
|
if (config.iss === 'unified-auth') {
|
|
71
71
|
const validateUrl = (0, txstate_utils_1.isNotBlank)(config.validateUrl)
|
|
72
72
|
? new URL(config.validateUrl, config.url)
|
|
73
|
-
: (
|
|
74
|
-
? new URL(process.env.UA_URL + '/validateToken')
|
|
75
|
-
: new URL('validateToken', config.url);
|
|
73
|
+
: new URL('validateToken', config.url);
|
|
76
74
|
const logoutUrl = (0, txstate_utils_1.isNotBlank)(config.logoutUrl)
|
|
77
75
|
? new URL(config.logoutUrl, config.url)
|
|
78
76
|
: (0, txstate_utils_1.isNotBlank)(process.env.UA_URL)
|
|
@@ -114,7 +112,7 @@ function tokenFromReq(req) {
|
|
|
114
112
|
const m = req?.headers.authorization?.match(/^bearer (.*)$/i);
|
|
115
113
|
if (m != null)
|
|
116
114
|
return m[1];
|
|
117
|
-
const m2 = req?.headers.cookie?.match(
|
|
115
|
+
const m2 = req?.headers.cookie?.match(uaCookieNameRegex);
|
|
118
116
|
if (m2 != null)
|
|
119
117
|
return m2[1];
|
|
120
118
|
}
|
|
@@ -184,7 +182,7 @@ function registerUaCookieRoutes(app) {
|
|
|
184
182
|
headers: {
|
|
185
183
|
type: 'object',
|
|
186
184
|
properties: {
|
|
187
|
-
cookie: { type: 'string', pattern: `${
|
|
185
|
+
cookie: { type: 'string', pattern: `${uaCookieName}=[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+` }
|
|
188
186
|
},
|
|
189
187
|
required: ['cookie']
|
|
190
188
|
}
|
|
@@ -194,7 +192,7 @@ function registerUaCookieRoutes(app) {
|
|
|
194
192
|
? `${req.auth.issuerConfig.logoutUrl.toString()}?unifiedJwt=${encodeURIComponent(req.auth.token)}`
|
|
195
193
|
: (process.env.PUBLIC_URL || new URL('..', req.url).toString());
|
|
196
194
|
return res
|
|
197
|
-
.header('Set-Cookie', `${
|
|
195
|
+
.header('Set-Cookie', `${uaCookieName}=; Path=/; Secure; HttpOnly; SameSite=Lax; Expires=Thu, 01 Jan 1970 00:00:00 GMT`)
|
|
198
196
|
.redirect(redirectUrl);
|
|
199
197
|
});
|
|
200
198
|
app.get('/.uaService', {
|
|
@@ -211,7 +209,7 @@ function registerUaCookieRoutes(app) {
|
|
|
211
209
|
}
|
|
212
210
|
}, async (req, res) => {
|
|
213
211
|
return res
|
|
214
|
-
.header('Set-Cookie', `${
|
|
212
|
+
.header('Set-Cookie', `${uaCookieName}=${req.query.unifiedJwt}; Path=/; Secure; HttpOnly; SameSite=Lax`)
|
|
215
213
|
.redirect(req.query.requestedUrl ?? (process.env.PUBLIC_URL || new URL('..', req.url).toString()));
|
|
216
214
|
});
|
|
217
215
|
/**
|
package/lib-esm/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export const ValidationError = ftxst.ValidationError
|
|
|
8
8
|
export const ValidationErrors = ftxst.ValidationErrors
|
|
9
9
|
export const unifiedAuthenticate = ftxst.unifiedAuthenticate
|
|
10
10
|
export const unifiedAuthenticateAll = ftxst.unifiedAuthenticateAll
|
|
11
|
+
export const registerUaCookieRoutes = ftxst.registerUaCookieRoutes
|
|
11
12
|
export const analyticsPlugin = ftxst.analyticsPlugin
|
|
12
13
|
export const AnalyticsClient = ftxst.AnalyticsClient
|
|
13
14
|
export const LoggingAnalyticsClient = ftxst.LoggingAnalyticsClient
|