fastify-txstate 3.6.0 → 3.6.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/lib/unified-auth.d.ts +0 -1
- package/lib/unified-auth.js +5 -6
- 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,7 @@ 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');
|
|
16
15
|
const tokenCache = new txstate_utils_1.Cache(async (token, req) => {
|
|
17
16
|
const claims = (0, jose_1.decodeJwt)(token);
|
|
18
17
|
let verifyKey;
|
|
@@ -114,7 +113,7 @@ function tokenFromReq(req) {
|
|
|
114
113
|
const m = req?.headers.authorization?.match(/^bearer (.*)$/i);
|
|
115
114
|
if (m != null)
|
|
116
115
|
return m[1];
|
|
117
|
-
const m2 = req?.headers.cookie?.match(new RegExp(`${
|
|
116
|
+
const m2 = req?.headers.cookie?.match(new RegExp(`${uaCookieName}=([^;]+)`));
|
|
118
117
|
if (m2 != null)
|
|
119
118
|
return m2[1];
|
|
120
119
|
}
|
|
@@ -184,7 +183,7 @@ function registerUaCookieRoutes(app) {
|
|
|
184
183
|
headers: {
|
|
185
184
|
type: 'object',
|
|
186
185
|
properties: {
|
|
187
|
-
cookie: { type: 'string', pattern: `${
|
|
186
|
+
cookie: { type: 'string', pattern: `${uaCookieName}=[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+` }
|
|
188
187
|
},
|
|
189
188
|
required: ['cookie']
|
|
190
189
|
}
|
|
@@ -194,7 +193,7 @@ function registerUaCookieRoutes(app) {
|
|
|
194
193
|
? `${req.auth.issuerConfig.logoutUrl.toString()}?unifiedJwt=${encodeURIComponent(req.auth.token)}`
|
|
195
194
|
: (process.env.PUBLIC_URL || new URL('..', req.url).toString());
|
|
196
195
|
return res
|
|
197
|
-
.header('Set-Cookie', `${
|
|
196
|
+
.header('Set-Cookie', `${uaCookieName}=; Path=/; Secure; HttpOnly; SameSite=Lax; Expires=Thu, 01 Jan 1970 00:00:00 GMT`)
|
|
198
197
|
.redirect(redirectUrl);
|
|
199
198
|
});
|
|
200
199
|
app.get('/.uaService', {
|
|
@@ -211,7 +210,7 @@ function registerUaCookieRoutes(app) {
|
|
|
211
210
|
}
|
|
212
211
|
}, async (req, res) => {
|
|
213
212
|
return res
|
|
214
|
-
.header('Set-Cookie', `${
|
|
213
|
+
.header('Set-Cookie', `${uaCookieName}=${req.query.unifiedJwt}; Path=/; Secure; HttpOnly; SameSite=Lax`)
|
|
215
214
|
.redirect(req.query.requestedUrl ?? (process.env.PUBLIC_URL || new URL('..', req.url).toString()));
|
|
216
215
|
});
|
|
217
216
|
/**
|
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
|