@frontegg/nextjs 6.7.11-alpha.4035916334 → 6.7.11-alpha.4036823874
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/CHANGELOG.md +1 -0
- package/{CookieManager-27107b90.js → CookieManager-0b48b7ab.js} +18 -5
- package/CookieManager-0b48b7ab.js.map +1 -0
- package/FronteggMiddleware.d.ts +8 -13
- package/client/index.js +1 -1
- package/common/CookieManager.d.ts +1 -1
- package/common/FronteggProxy.d.ts +22 -0
- package/common/helpers.d.ts +1 -1
- package/common/index.js +3 -3
- package/{createGetSession-bee8af0a.js → createGetSession-ba9eb34d.js} +2 -2
- package/createGetSession-ba9eb34d.js.map +1 -0
- package/edge/index.js +2 -2
- package/{helpers-b15628e9.js → helpers-52cd4d67.js} +6 -12
- package/helpers-52cd4d67.js.map +1 -0
- package/index.js +127 -96
- package/package.json +1 -1
- package/server/index.js +3 -3
- package/CookieManager-27107b90.js.map +0 -1
- package/createGetSession-bee8af0a.js.map +0 -1
- package/helpers-b15628e9.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
- FR-9816 - fix version
|
|
26
26
|
|
|
27
27
|
### NextJS Wrapper 6.7.11:
|
|
28
|
+
- FR-10557 - Improve FronteggMiddleware request handler
|
|
28
29
|
- update frontegg manually
|
|
29
30
|
- FR-10379 - disable refresh token by default for ssr
|
|
30
31
|
- FR-10141 - Added support for logout on hosted login
|
|
@@ -160,6 +160,12 @@ var CookieManager = /** @class */ (function () {
|
|
|
160
160
|
cookiesToRemove.forEach(function (name) {
|
|
161
161
|
allEmptyCookies.push.apply(allEmptyCookies, _this.createEmptySingleCookie(name, isSecured, cookieDomain));
|
|
162
162
|
});
|
|
163
|
+
// TODO: remove replace in the next major v7
|
|
164
|
+
var fixedRefreshToken = _this.createEmptySingleCookie("fe_refresh_".concat(FronteggConfig$1.clientId), isSecured, cookieDomain);
|
|
165
|
+
var refreshTokenCookie = _this.createEmptySingleCookie("fe_refresh_".concat(FronteggConfig$1.clientId.replace('-', '')), isSecured, cookieDomain);
|
|
166
|
+
var solidRefreshTokenCookie = _this.createEmptySingleCookie("fe_refresh_".concat(FronteggConfig$1.clientId.replace(/-/g, '')), isSecured, cookieDomain);
|
|
167
|
+
var refreshTokenCookies = __spreadArray(__spreadArray(__spreadArray([], fixedRefreshToken, true), refreshTokenCookie, true), solidRefreshTokenCookie, true);
|
|
168
|
+
allEmptyCookies.push.apply(allEmptyCookies, refreshTokenCookies);
|
|
163
169
|
return allEmptyCookies;
|
|
164
170
|
};
|
|
165
171
|
this.getCookiesToRemove = function (req) {
|
|
@@ -185,17 +191,24 @@ var CookieManager = /** @class */ (function () {
|
|
|
185
191
|
return [];
|
|
186
192
|
}
|
|
187
193
|
};
|
|
188
|
-
this.
|
|
194
|
+
this.modifySetCookie = function (setCookieValue, isSecured) {
|
|
189
195
|
if (!setCookieValue) {
|
|
190
196
|
return setCookieValue;
|
|
191
197
|
}
|
|
192
198
|
if (setCookieValue.length > 0) {
|
|
193
199
|
return setCookieValue.map(function (c) {
|
|
194
200
|
var cookie = c.split('; ');
|
|
195
|
-
if (isSecured) {
|
|
196
|
-
return
|
|
201
|
+
if (!isSecured) {
|
|
202
|
+
cookie = cookie.filter(function (property) { return property !== 'Secure' && property !== 'SameSite=None'; });
|
|
197
203
|
}
|
|
198
|
-
return cookie
|
|
204
|
+
return cookie
|
|
205
|
+
.map(function (property) {
|
|
206
|
+
if (property.toLowerCase() === "domain=".concat(FronteggConfig$1.baseUrlHost)) {
|
|
207
|
+
return "Domain=".concat(FronteggConfig$1.cookieDomain);
|
|
208
|
+
}
|
|
209
|
+
return property;
|
|
210
|
+
})
|
|
211
|
+
.join(';');
|
|
199
212
|
});
|
|
200
213
|
}
|
|
201
214
|
return setCookieValue;
|
|
@@ -306,4 +319,4 @@ var CookieManager = /** @class */ (function () {
|
|
|
306
319
|
var CookieManager$1 = new CookieManager();
|
|
307
320
|
|
|
308
321
|
export { CookieManager$1 as C, FronteggConfig$1 as F, COOKIE_MAX_LENGTH as a, fronteggErrors as f };
|
|
309
|
-
//# sourceMappingURL=CookieManager-
|
|
322
|
+
//# sourceMappingURL=CookieManager-0b48b7ab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CookieManager-0b48b7ab.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/FronteggMiddleware.d.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[key: string]: string;
|
|
10
|
-
} | {
|
|
11
|
-
patternStr: string;
|
|
12
|
-
replaceStr: string;
|
|
13
|
-
}[]) => string;
|
|
2
|
+
export declare const config: {
|
|
3
|
+
api: {
|
|
4
|
+
externalResolver: boolean;
|
|
5
|
+
bodyParser: boolean;
|
|
6
|
+
responseLimit: boolean;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
14
9
|
/**
|
|
15
10
|
* Next.js HTTP Proxy Middleware
|
|
16
11
|
* @see https://nextjs.org/docs/api-routes/api-middlewares
|
|
17
12
|
* @param {NextApiRequest} req
|
|
18
13
|
* @param {NextApiResponse} res
|
|
19
14
|
*/
|
|
20
|
-
export declare function fronteggMiddleware(req: NextApiRequest, res: NextApiResponse): Promise<
|
|
15
|
+
export declare function fronteggMiddleware(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
package/client/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { __assign, __spreadArray } from 'tslib';
|
|
3
|
-
import { F as FronteggConfig } from '../CookieManager-
|
|
3
|
+
import { F as FronteggConfig } from '../CookieManager-0b48b7ab.js';
|
|
4
4
|
import 'iron-session';
|
|
5
5
|
import 'jose';
|
|
6
6
|
import '../api-25516652.js';
|
|
@@ -35,7 +35,7 @@ declare class CookieManager {
|
|
|
35
35
|
createEmptyCookies: (isSecured: boolean, cookieDomain: string, cookiesToRemove: string[]) => string[];
|
|
36
36
|
getCookiesToRemove: (req?: RequestType) => string[];
|
|
37
37
|
removeCookies({ cookieNames, isSecured, cookieDomain, res, req }: RemoveCookiesArguments): void;
|
|
38
|
-
|
|
38
|
+
modifySetCookie: (setCookieValue: string[] | undefined, isSecured: boolean) => string[] | undefined;
|
|
39
39
|
}
|
|
40
40
|
declare const _default: CookieManager;
|
|
41
41
|
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import httpProxy from 'http-proxy';
|
|
2
|
+
/**
|
|
3
|
+
* @see https://www.npmjs.com/package/http-proxy
|
|
4
|
+
*/
|
|
5
|
+
export declare const FronteggProxy: httpProxy;
|
|
6
|
+
/**
|
|
7
|
+
* If pattern information matching the input url information is found in the `pathRewrite` array,
|
|
8
|
+
* the url value is partially replaced with the `pathRewrite.replaceStr` value.
|
|
9
|
+
* @param url
|
|
10
|
+
* @param pathRewrite
|
|
11
|
+
*/
|
|
12
|
+
export declare const rewritePath: (url: string, pathRewrite: {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
} | {
|
|
15
|
+
patternStr: string;
|
|
16
|
+
replaceStr: string;
|
|
17
|
+
}[]) => string;
|
|
18
|
+
export declare const fronteggPathRewrite: {
|
|
19
|
+
patternStr: string;
|
|
20
|
+
replaceStr: string;
|
|
21
|
+
}[];
|
|
22
|
+
export declare const isFronteggLogoutUrl: (url: string) => boolean;
|
package/common/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FronteggNextJSSession, FronteggUserTokens, AllUserData } from './types';
|
|
2
|
-
export declare function createSessionFromAccessToken(
|
|
2
|
+
export declare function createSessionFromAccessToken(data: any): Promise<[string, any, string] | []>;
|
|
3
3
|
export declare function getTokensFromCookie(cookie?: string): Promise<FronteggUserTokens | undefined>;
|
|
4
4
|
type UserDataArguments = {
|
|
5
5
|
getSession: () => Promise<FronteggNextJSSession | undefined | null>;
|
package/common/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { a as COOKIE_MAX_LENGTH, C as CookieManager, F as FronteggConfig, f as fronteggErrors } from '../CookieManager-
|
|
2
|
-
export { c as createSessionFromAccessToken, a as getAllUserData, g as getTokensFromCookie } from '../helpers-
|
|
3
|
-
export { c as createGetSession } from '../createGetSession-
|
|
1
|
+
export { a as COOKIE_MAX_LENGTH, C as CookieManager, F as FronteggConfig, f as fronteggErrors } from '../CookieManager-0b48b7ab.js';
|
|
2
|
+
export { c as createSessionFromAccessToken, a as getAllUserData, g as getTokensFromCookie } from '../helpers-52cd4d67.js';
|
|
3
|
+
export { c as createGetSession } from '../createGetSession-ba9eb34d.js';
|
|
4
4
|
import 'tslib';
|
|
5
5
|
import 'cookie';
|
|
6
6
|
import 'jose';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __generator } from 'tslib';
|
|
2
2
|
import { jwtVerify } from 'jose';
|
|
3
|
-
import { F as FronteggConfig } from './CookieManager-
|
|
3
|
+
import { F as FronteggConfig } from './CookieManager-0b48b7ab.js';
|
|
4
4
|
|
|
5
5
|
var createGetSession = function (_a) {
|
|
6
6
|
var getCookie = _a.getCookie, cookieResolver = _a.cookieResolver;
|
|
@@ -47,4 +47,4 @@ var createGetSession = function (_a) {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
export { createGetSession as c };
|
|
50
|
-
//# sourceMappingURL=createGetSession-
|
|
50
|
+
//# sourceMappingURL=createGetSession-ba9eb34d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGetSession-ba9eb34d.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/edge/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __awaiter, __generator } from 'tslib';
|
|
2
2
|
import { unsealData } from 'iron-session/edge';
|
|
3
|
-
import { C as CookieManager, F as FronteggConfig } from '../CookieManager-
|
|
4
|
-
import { c as createGetSession } from '../createGetSession-
|
|
3
|
+
import { C as CookieManager, F as FronteggConfig } from '../CookieManager-0b48b7ab.js';
|
|
4
|
+
import { c as createGetSession } from '../createGetSession-ba9eb34d.js';
|
|
5
5
|
import 'cookie';
|
|
6
6
|
import 'jose';
|
|
7
7
|
|
|
@@ -4,21 +4,19 @@ import { jwtVerify } from 'jose';
|
|
|
4
4
|
import { g as getUsers, a as getTenants } from './api-25516652.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import '@frontegg/react-hooks';
|
|
7
|
-
import { F as FronteggConfig } from './CookieManager-
|
|
7
|
+
import { F as FronteggConfig } from './CookieManager-0b48b7ab.js';
|
|
8
8
|
|
|
9
9
|
var calculateExpiresInFromExp = function (exp) { return Math.floor((exp * 1000 - Date.now()) / 1000); };
|
|
10
10
|
|
|
11
|
-
function createSessionFromAccessToken(
|
|
11
|
+
function createSessionFromAccessToken(data) {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
return __awaiter(this, void 0, void 0, function () {
|
|
14
|
-
var
|
|
14
|
+
var accessToken, refreshToken, publicKey, decodedJwt, stringifySession, session;
|
|
15
15
|
return __generator(this, function (_c) {
|
|
16
16
|
switch (_c.label) {
|
|
17
17
|
case 0:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
accessToken = (_a = data === null || data === void 0 ? void 0 : data.accessToken) !== null && _a !== void 0 ? _a : data.access_token;
|
|
21
|
-
refreshToken = (_b = data === null || data === void 0 ? void 0 : data.refreshToken) !== null && _b !== void 0 ? _b : data.refresh_token;
|
|
18
|
+
accessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : data.access_token;
|
|
19
|
+
refreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : data.refresh_token;
|
|
22
20
|
return [4 /*yield*/, FronteggConfig.getJwtPublicKey()];
|
|
23
21
|
case 1:
|
|
24
22
|
publicKey = _c.sent();
|
|
@@ -34,10 +32,6 @@ function createSessionFromAccessToken(output) {
|
|
|
34
32
|
case 3:
|
|
35
33
|
session = _c.sent();
|
|
36
34
|
return [2 /*return*/, [session, decodedJwt, refreshToken]];
|
|
37
|
-
case 4:
|
|
38
|
-
_c.sent();
|
|
39
|
-
return [2 /*return*/, []];
|
|
40
|
-
case 5: return [2 /*return*/];
|
|
41
35
|
}
|
|
42
36
|
});
|
|
43
37
|
});
|
|
@@ -93,4 +87,4 @@ var getAllUserData = function (_a) {
|
|
|
93
87
|
};
|
|
94
88
|
|
|
95
89
|
export { getAllUserData as a, createSessionFromAccessToken as c, getTokensFromCookie as g };
|
|
96
|
-
//# sourceMappingURL=helpers-
|
|
90
|
+
//# sourceMappingURL=helpers-52cd4d67.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers-52cd4d67.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/index.js
CHANGED
|
@@ -397,17 +397,15 @@ var getTenants = function (headers) { return tslib.__awaiter(void 0, void 0, voi
|
|
|
397
397
|
});
|
|
398
398
|
}); };
|
|
399
399
|
|
|
400
|
-
function createSessionFromAccessToken(
|
|
400
|
+
function createSessionFromAccessToken(data) {
|
|
401
401
|
var _a, _b;
|
|
402
402
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
403
|
-
var
|
|
403
|
+
var accessToken, refreshToken, publicKey, decodedJwt, stringifySession, session;
|
|
404
404
|
return tslib.__generator(this, function (_c) {
|
|
405
405
|
switch (_c.label) {
|
|
406
406
|
case 0:
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
accessToken = (_a = data === null || data === void 0 ? void 0 : data.accessToken) !== null && _a !== void 0 ? _a : data.access_token;
|
|
410
|
-
refreshToken = (_b = data === null || data === void 0 ? void 0 : data.refreshToken) !== null && _b !== void 0 ? _b : data.refresh_token;
|
|
407
|
+
accessToken = (_a = data.accessToken) !== null && _a !== void 0 ? _a : data.access_token;
|
|
408
|
+
refreshToken = (_b = data.refreshToken) !== null && _b !== void 0 ? _b : data.refresh_token;
|
|
411
409
|
return [4 /*yield*/, fronteggConfig.getJwtPublicKey()];
|
|
412
410
|
case 1:
|
|
413
411
|
publicKey = _c.sent();
|
|
@@ -423,10 +421,6 @@ function createSessionFromAccessToken(output) {
|
|
|
423
421
|
case 3:
|
|
424
422
|
session = _c.sent();
|
|
425
423
|
return [2 /*return*/, [session, decodedJwt, refreshToken]];
|
|
426
|
-
case 4:
|
|
427
|
-
_c.sent();
|
|
428
|
-
return [2 /*return*/, []];
|
|
429
|
-
case 5: return [2 /*return*/];
|
|
430
424
|
}
|
|
431
425
|
});
|
|
432
426
|
});
|
|
@@ -565,6 +559,12 @@ var CookieManager = /** @class */ (function () {
|
|
|
565
559
|
cookiesToRemove.forEach(function (name) {
|
|
566
560
|
allEmptyCookies.push.apply(allEmptyCookies, _this.createEmptySingleCookie(name, isSecured, cookieDomain));
|
|
567
561
|
});
|
|
562
|
+
// TODO: remove replace in the next major v7
|
|
563
|
+
var fixedRefreshToken = _this.createEmptySingleCookie("fe_refresh_".concat(fronteggConfig.clientId), isSecured, cookieDomain);
|
|
564
|
+
var refreshTokenCookie = _this.createEmptySingleCookie("fe_refresh_".concat(fronteggConfig.clientId.replace('-', '')), isSecured, cookieDomain);
|
|
565
|
+
var solidRefreshTokenCookie = _this.createEmptySingleCookie("fe_refresh_".concat(fronteggConfig.clientId.replace(/-/g, '')), isSecured, cookieDomain);
|
|
566
|
+
var refreshTokenCookies = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], fixedRefreshToken, true), refreshTokenCookie, true), solidRefreshTokenCookie, true);
|
|
567
|
+
allEmptyCookies.push.apply(allEmptyCookies, refreshTokenCookies);
|
|
568
568
|
return allEmptyCookies;
|
|
569
569
|
};
|
|
570
570
|
this.getCookiesToRemove = function (req) {
|
|
@@ -590,17 +590,24 @@ var CookieManager = /** @class */ (function () {
|
|
|
590
590
|
return [];
|
|
591
591
|
}
|
|
592
592
|
};
|
|
593
|
-
this.
|
|
593
|
+
this.modifySetCookie = function (setCookieValue, isSecured) {
|
|
594
594
|
if (!setCookieValue) {
|
|
595
595
|
return setCookieValue;
|
|
596
596
|
}
|
|
597
597
|
if (setCookieValue.length > 0) {
|
|
598
598
|
return setCookieValue.map(function (c) {
|
|
599
599
|
var cookie = c.split('; ');
|
|
600
|
-
if (isSecured) {
|
|
601
|
-
return
|
|
600
|
+
if (!isSecured) {
|
|
601
|
+
cookie = cookie.filter(function (property) { return property !== 'Secure' && property !== 'SameSite=None'; });
|
|
602
602
|
}
|
|
603
|
-
return cookie
|
|
603
|
+
return cookie
|
|
604
|
+
.map(function (property) {
|
|
605
|
+
if (property.toLowerCase() === "domain=".concat(fronteggConfig.baseUrlHost)) {
|
|
606
|
+
return "Domain=".concat(fronteggConfig.cookieDomain);
|
|
607
|
+
}
|
|
608
|
+
return property;
|
|
609
|
+
})
|
|
610
|
+
.join(';');
|
|
604
611
|
});
|
|
605
612
|
}
|
|
606
613
|
return setCookieValue;
|
|
@@ -1068,15 +1075,11 @@ var withFronteggApp = function (app, options) {
|
|
|
1068
1075
|
/**
|
|
1069
1076
|
* @see https://www.npmjs.com/package/http-proxy
|
|
1070
1077
|
*/
|
|
1071
|
-
var
|
|
1078
|
+
var FronteggProxy = httpProxy__default["default"].createProxyServer({
|
|
1072
1079
|
target: process.env['FRONTEGG_BASE_URL'],
|
|
1080
|
+
autoRewrite: false,
|
|
1081
|
+
followRedirects: true,
|
|
1073
1082
|
});
|
|
1074
|
-
/**
|
|
1075
|
-
* Please refer to the following links for the specification document for HTTP.
|
|
1076
|
-
* @see https://tools.ietf.org/html/rfc7231
|
|
1077
|
-
* @see https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
|
|
1078
|
-
*/
|
|
1079
|
-
var hasRequestBodyMethods = ['HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH'];
|
|
1080
1083
|
/**
|
|
1081
1084
|
* If pattern information matching the input url information is found in the `pathRewrite` array,
|
|
1082
1085
|
* the url value is partially replaced with the `pathRewrite.replaceStr` value.
|
|
@@ -1106,100 +1109,128 @@ var rewritePath = function (url, pathRewrite) {
|
|
|
1106
1109
|
}
|
|
1107
1110
|
return url;
|
|
1108
1111
|
};
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
function
|
|
1116
|
-
|
|
1117
|
-
|
|
1112
|
+
var fronteggPathRewrite = [
|
|
1113
|
+
{
|
|
1114
|
+
patternStr: '^/api/',
|
|
1115
|
+
replaceStr: '/',
|
|
1116
|
+
},
|
|
1117
|
+
];
|
|
1118
|
+
var isFronteggLogoutUrl = function (url) {
|
|
1119
|
+
return (restApi.fronteggAuthApiRoutes.filter(function (path) { return path.endsWith('/logout'); }).findIndex(function (route) { return url.endsWith(route); }) >= 0);
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
var config = {
|
|
1123
|
+
api: {
|
|
1124
|
+
externalResolver: true,
|
|
1125
|
+
bodyParser: false,
|
|
1126
|
+
responseLimit: false,
|
|
1127
|
+
},
|
|
1128
|
+
};
|
|
1129
|
+
var middlewarePromise = function (req, res) {
|
|
1130
|
+
return new Promise(function (resolve) {
|
|
1118
1131
|
var _a;
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
patternStr: '^/api/',
|
|
1122
|
-
replaceStr: '/',
|
|
1123
|
-
},
|
|
1124
|
-
];
|
|
1125
|
-
if (pathRewrite) {
|
|
1126
|
-
req.url = rewritePath(req.url, pathRewrite);
|
|
1127
|
-
}
|
|
1128
|
-
if (hasRequestBodyMethods.indexOf(req.method) >= 0 && typeof req.body === 'object') {
|
|
1129
|
-
req.body = JSON.stringify(req.body);
|
|
1130
|
-
}
|
|
1132
|
+
req.url = rewritePath((_a = req.url) !== null && _a !== void 0 ? _a : '/', fronteggPathRewrite);
|
|
1133
|
+
// console.log('FronteggMiddleware.start', { url: req.url });
|
|
1131
1134
|
var isSecured = new URL(fronteggConfig.appUrl).protocol === 'https:';
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1135
|
+
FronteggProxy.once('proxyReq', function (proxyReq, req) {
|
|
1136
|
+
try {
|
|
1137
|
+
if (req.body) {
|
|
1138
|
+
var bodyData = JSON.stringify(req.body);
|
|
1139
|
+
// in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json
|
|
1140
|
+
proxyReq.setHeader('Content-Type', 'application/json');
|
|
1141
|
+
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
1142
|
+
// stream the content
|
|
1143
|
+
proxyReq.write(bodyData);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
catch (e) {
|
|
1147
|
+
console.error("once('proxyReq'), ERROR", e);
|
|
1137
1148
|
}
|
|
1138
1149
|
})
|
|
1139
|
-
.once('proxyRes', function (proxyRes, req
|
|
1140
|
-
proxyRes.headers['set-cookie'] = CookieManager$1.modifySetCookieIfUnsecure(proxyRes.headers['set-cookie'], isSecured);
|
|
1141
|
-
var _end = res.end;
|
|
1150
|
+
.once('proxyRes', function (proxyRes, req) {
|
|
1142
1151
|
var buffer = new Buffer('');
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1152
|
+
var totalLength = 0;
|
|
1153
|
+
proxyRes.on('data', function (chunk) {
|
|
1154
|
+
totalLength += chunk.length;
|
|
1155
|
+
buffer = Buffer.concat([buffer, chunk], totalLength);
|
|
1156
|
+
});
|
|
1157
|
+
proxyRes.on('end', function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
|
|
1158
|
+
var url, statusCode, isSuccess, bodyStr, isLogout, body, _a, session, decodedJwt, cookies, sessionCookie, e_1;
|
|
1159
|
+
var _b, _c;
|
|
1160
|
+
return tslib.__generator(this, function (_d) {
|
|
1161
|
+
switch (_d.label) {
|
|
1151
1162
|
case 0:
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
res
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1163
|
+
_d.trys.push([0, 4, , 5]);
|
|
1164
|
+
url = req.url;
|
|
1165
|
+
statusCode = (_b = proxyRes.statusCode) !== null && _b !== void 0 ? _b : 500;
|
|
1166
|
+
isSuccess = statusCode >= 200 && statusCode < 300;
|
|
1167
|
+
bodyStr = buffer.toString('utf-8');
|
|
1168
|
+
isLogout = isFronteggLogoutUrl(url);
|
|
1169
|
+
if (isLogout) {
|
|
1170
|
+
CookieManager$1.removeCookies({
|
|
1171
|
+
isSecured: isSecured,
|
|
1172
|
+
cookieDomain: fronteggConfig.cookieDomain,
|
|
1173
|
+
res: res,
|
|
1174
|
+
req: req,
|
|
1175
|
+
});
|
|
1176
|
+
res.status(statusCode).end(bodyStr);
|
|
1177
|
+
resolve();
|
|
1178
|
+
return [2 /*return*/];
|
|
1179
|
+
}
|
|
1180
|
+
if (!isSuccess) return [3 /*break*/, 2];
|
|
1181
|
+
body = JSON.parse(bodyStr);
|
|
1182
|
+
return [4 /*yield*/, createSessionFromAccessToken(body)];
|
|
1183
|
+
case 1:
|
|
1184
|
+
_a = _d.sent(), session = _a[0], decodedJwt = _a[1];
|
|
1185
|
+
cookies = (_c = CookieManager$1.modifySetCookie(proxyRes.headers['set-cookie'], isSecured)) !== null && _c !== void 0 ? _c : [];
|
|
1172
1186
|
if (session) {
|
|
1173
1187
|
sessionCookie = CookieManager$1.createCookie({
|
|
1174
1188
|
value: session,
|
|
1175
1189
|
expires: new Date(decodedJwt.exp * 1000),
|
|
1176
1190
|
isSecured: isSecured,
|
|
1177
1191
|
});
|
|
1178
|
-
|
|
1192
|
+
cookies.push.apply(cookies, sessionCookie);
|
|
1179
1193
|
}
|
|
1180
|
-
|
|
1194
|
+
res.setHeader('set-cookie', cookies);
|
|
1195
|
+
res.status(statusCode).end(bodyStr);
|
|
1196
|
+
return [3 /*break*/, 3];
|
|
1197
|
+
case 2:
|
|
1198
|
+
console.error('[ERROR] FronteggMiddleware', { url: url, statusCode: statusCode, bodyStr: bodyStr });
|
|
1199
|
+
res.status(statusCode).send(bodyStr);
|
|
1200
|
+
_d.label = 3;
|
|
1181
1201
|
case 3:
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1202
|
+
resolve();
|
|
1203
|
+
return [3 /*break*/, 5];
|
|
1204
|
+
case 4:
|
|
1205
|
+
e_1 = _d.sent();
|
|
1206
|
+
console.error('[ERROR] FronteggMiddleware', 'proxy failed to send request', e_1);
|
|
1207
|
+
res.status(500).end('Internal Server Error');
|
|
1208
|
+
resolve();
|
|
1209
|
+
return [3 /*break*/, 5];
|
|
1210
|
+
case 5: return [2 /*return*/];
|
|
1187
1211
|
}
|
|
1188
1212
|
});
|
|
1189
1213
|
}); });
|
|
1190
|
-
// disable default behavior to read jwt
|
|
1191
|
-
// @ts-ignore
|
|
1192
|
-
serverResponse.write = function () { return undefined; };
|
|
1193
|
-
// @ts-ignore
|
|
1194
|
-
serverResponse.end = function () { return undefined; };
|
|
1195
1214
|
})
|
|
1196
|
-
.once('error', reject)
|
|
1197
1215
|
.web(req, res, {
|
|
1198
1216
|
changeOrigin: true,
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1217
|
+
selfHandleResponse: true,
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
};
|
|
1221
|
+
/**
|
|
1222
|
+
* Next.js HTTP Proxy Middleware
|
|
1223
|
+
* @see https://nextjs.org/docs/api-routes/api-middlewares
|
|
1224
|
+
* @param {NextApiRequest} req
|
|
1225
|
+
* @param {NextApiResponse} res
|
|
1226
|
+
*/
|
|
1227
|
+
function fronteggMiddleware(req, res) {
|
|
1228
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1229
|
+
return tslib.__generator(this, function (_a) {
|
|
1230
|
+
switch (_a.label) {
|
|
1231
|
+
case 0: return [4 /*yield*/, middlewarePromise(req, res)];
|
|
1232
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
1233
|
+
}
|
|
1203
1234
|
});
|
|
1204
1235
|
});
|
|
1205
1236
|
}
|
|
@@ -1216,6 +1247,7 @@ exports.FronteggProvider = FronteggProvider;
|
|
|
1216
1247
|
exports.FronteggProviderNoSSR = FronteggProviderNoSSR;
|
|
1217
1248
|
exports.FronteggRouter = FronteggRouter;
|
|
1218
1249
|
exports.FronteggRouterProps = FronteggRouterProps;
|
|
1250
|
+
exports.config = config;
|
|
1219
1251
|
exports.createGetSession = createGetSession;
|
|
1220
1252
|
exports.createSessionFromAccessToken = createSessionFromAccessToken;
|
|
1221
1253
|
exports.fronteggErrors = fronteggErrors;
|
|
@@ -1223,7 +1255,6 @@ exports.fronteggMiddleware = fronteggMiddleware;
|
|
|
1223
1255
|
exports.getAllUserData = getAllUserData;
|
|
1224
1256
|
exports.getSession = getSession;
|
|
1225
1257
|
exports.getTokensFromCookie = getTokensFromCookie;
|
|
1226
|
-
exports.rewritePath = rewritePath;
|
|
1227
1258
|
exports.withFronteggApp = withFronteggApp;
|
|
1228
1259
|
exports.withSSRSession = withSSRSession;
|
|
1229
1260
|
Object.keys(reactHooks).forEach(function (k) {
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __awaiter, __generator, __rest, __assign } from 'tslib';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { cookies, headers } from 'next/headers';
|
|
4
|
-
import { C as CookieManager } from '../CookieManager-
|
|
5
|
-
import { g as getTokensFromCookie, a as getAllUserData } from '../helpers-
|
|
6
|
-
import { c as createGetSession } from '../createGetSession-
|
|
4
|
+
import { C as CookieManager } from '../CookieManager-0b48b7ab.js';
|
|
5
|
+
import { g as getTokensFromCookie, a as getAllUserData } from '../helpers-52cd4d67.js';
|
|
6
|
+
import { c as createGetSession } from '../createGetSession-ba9eb34d.js';
|
|
7
7
|
import 'jose';
|
|
8
8
|
import '@frontegg/react-hooks';
|
|
9
9
|
import '@frontegg/rest-api';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CookieManager-27107b90.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createGetSession-bee8af0a.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/helpers-b15628e9.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers-b15628e9.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|