@frontegg/nextjs 6.7.20 → 6.7.21-alpha.4441481917
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 +10 -0
- package/README.md +19 -37
- package/api/index.d.ts +19 -0
- package/api/index.js +78 -0
- package/api/index.js.map +1 -0
- package/api/package.json +6 -0
- package/api/urls.d.ts +33 -0
- package/api/urls.js +46 -0
- package/api/urls.js.map +1 -0
- package/api/utils.d.ts +46 -0
- package/api/utils.js +108 -0
- package/api/utils.js.map +1 -0
- package/app/ClientFronteggProvider.d.ts +3 -0
- package/app/ClientFronteggProvider.js +25 -0
- package/app/ClientFronteggProvider.js.map +1 -0
- package/app/FronteggAppProvider.d.ts +4 -0
- package/app/FronteggAppProvider.js +17 -0
- package/app/FronteggAppProvider.js.map +1 -0
- package/{client → app}/FronteggAppRouter.d.ts +11 -10
- package/app/FronteggAppRouter.js +31 -0
- package/app/FronteggAppRouter.js.map +1 -0
- package/app/helpers.d.ts +5 -0
- package/app/helpers.js +32 -0
- package/app/helpers.js.map +1 -0
- package/app/index.d.ts +4 -0
- package/app/index.js +4 -0
- package/app/index.js.map +1 -0
- package/app/package.json +6 -0
- package/common/{client/AppContext.d.ts → AppContext.d.ts} +4 -4
- package/common/AppContext.js +6 -0
- package/common/AppContext.js.map +1 -0
- package/{AuthorizedContent.d.ts → common/AuthorizedContent.d.ts} +9 -8
- package/common/AuthorizedContent.js +48 -0
- package/common/AuthorizedContent.js.map +1 -0
- package/common/{client/FronteggBaseProvider.d.ts → FronteggBaseProvider.d.ts} +3 -3
- package/common/FronteggBaseProvider.js +67 -0
- package/common/FronteggBaseProvider.js.map +1 -0
- package/common/FronteggRouterBase.d.ts +9 -0
- package/common/FronteggRouterBase.js +42 -0
- package/common/FronteggRouterBase.js.map +1 -0
- package/common/helpers.d.ts +3 -9
- package/common/helpers.js +24 -0
- package/common/helpers.js.map +1 -0
- package/common/index.d.ts +4 -6
- package/common/index.js +5 -10
- package/common/index.js.map +1 -1
- package/common/package.json +6 -0
- package/common/useRequestAuthorizeSSR.d.ts +5 -0
- package/common/useRequestAuthorizeSSR.js +24 -0
- package/common/useRequestAuthorizeSSR.js.map +1 -0
- package/config/constants.d.ts +57 -0
- package/config/constants.js +13 -0
- package/config/constants.js.map +1 -0
- package/config/helpers.d.ts +28 -0
- package/config/helpers.js +87 -0
- package/config/helpers.js.map +1 -0
- package/config/index.d.ts +24 -0
- package/config/index.js +82 -0
- package/config/index.js.map +1 -0
- package/config/package.json +6 -0
- package/config/types.d.ts +18 -0
- package/config/types.js +2 -0
- package/config/types.js.map +1 -0
- package/edge/getSessionOnEdge.d.ts +3 -2
- package/edge/getSessionOnEdge.js +8 -0
- package/edge/getSessionOnEdge.js.map +1 -0
- package/edge/index.d.ts +3 -2
- package/edge/index.js +4 -64
- package/edge/index.js.map +1 -1
- package/edge/package.json +6 -0
- package/edge/redirectToLogin.d.ts +2 -0
- package/edge/redirectToLogin.js +9 -0
- package/edge/redirectToLogin.js.map +1 -0
- package/edge/shouldBypassMiddleware.d.ts +21 -7
- package/edge/shouldBypassMiddleware.js +42 -0
- package/edge/shouldBypassMiddleware.js.map +1 -0
- package/index.d.ts +7 -11
- package/index.js +13 -1401
- package/index.js.map +1 -1
- package/middleware/FronteggApiMiddleware.d.ts +8 -0
- package/middleware/FronteggApiMiddleware.js +28 -0
- package/middleware/FronteggApiMiddleware.js.map +1 -0
- package/middleware/FronteggProxy.d.ts +4 -0
- package/middleware/FronteggProxy.js +24 -0
- package/middleware/FronteggProxy.js.map +1 -0
- package/middleware/ProxyRequestCallback.d.ts +13 -0
- package/middleware/ProxyRequestCallback.js +48 -0
- package/middleware/ProxyRequestCallback.js.map +1 -0
- package/middleware/ProxyResponseCallback.d.ts +13 -0
- package/middleware/ProxyResponseCallback.js +103 -0
- package/middleware/ProxyResponseCallback.js.map +1 -0
- package/middleware/constants.d.ts +8 -0
- package/middleware/constants.js +9 -0
- package/middleware/constants.js.map +1 -0
- package/{common/FronteggProxy.d.ts → middleware/helpers.d.ts} +13 -26
- package/middleware/helpers.js +35 -0
- package/middleware/helpers.js.map +1 -0
- package/middleware/index.d.ts +23 -0
- package/middleware/index.js +24 -0
- package/middleware/index.js.map +1 -0
- package/middleware/package.json +6 -0
- package/no-ssr/ExpireInListener.d.ts +2 -0
- package/no-ssr/ExpireInListener.js +22 -0
- package/no-ssr/ExpireInListener.js.map +1 -0
- package/{FronteggProviderNoSSR.d.ts → no-ssr/FronteggProviderNoSSR.d.ts} +4 -4
- package/no-ssr/FronteggProviderNoSSR.js +76 -0
- package/no-ssr/FronteggProviderNoSSR.js.map +1 -0
- package/no-ssr/index.d.ts +2 -0
- package/no-ssr/index.js +2 -0
- package/no-ssr/index.js.map +1 -0
- package/no-ssr/package.json +6 -0
- package/package.json +6 -7
- package/pages/FronteggPagesProvider/index.d.ts +4 -0
- package/pages/FronteggPagesProvider/index.js +24 -0
- package/pages/FronteggPagesProvider/index.js.map +1 -0
- package/pages/FronteggPagesProvider/package.json +6 -0
- package/{FronteggRouter.d.ts → pages/FronteggRouter/FronteggRouter.d.ts} +6 -5
- package/pages/FronteggRouter/FronteggRouter.js +38 -0
- package/pages/FronteggRouter/FronteggRouter.js.map +1 -0
- package/pages/FronteggRouter/index.d.ts +26 -0
- package/pages/FronteggRouter/index.js +27 -0
- package/pages/FronteggRouter/index.js.map +1 -0
- package/pages/FronteggRouter/package.json +6 -0
- package/{session.d.ts → pages/helpers.d.ts} +10 -10
- package/pages/helpers.js +31 -0
- package/pages/helpers.js.map +1 -0
- package/pages/index.d.ts +3 -0
- package/pages/index.js +4 -0
- package/pages/index.js.map +1 -0
- package/pages/package.json +6 -0
- package/pages/withFronteggApp/index.d.ts +2 -0
- package/pages/withFronteggApp/index.js +2 -0
- package/pages/withFronteggApp/index.js.map +1 -0
- package/pages/withFronteggApp/package.json +6 -0
- package/pages/withFronteggApp/types.d.ts +12 -0
- package/pages/withFronteggApp/types.js +2 -0
- package/pages/withFronteggApp/types.js.map +1 -0
- package/pages/withFronteggApp/withFronteggApp.d.ts +2 -0
- package/pages/withFronteggApp/withFronteggApp.js +62 -0
- package/pages/withFronteggApp/withFronteggApp.js.map +1 -0
- package/sdkVersion.d.ts +4 -4
- package/sdkVersion.js +4 -0
- package/sdkVersion.js.map +1 -0
- package/{common/types.d.ts → types/index.d.ts} +80 -74
- package/types/index.js +2 -0
- package/types/index.js.map +1 -0
- package/types/package.json +6 -0
- package/utils/common/constants.d.ts +12 -0
- package/utils/common/constants.js +14 -0
- package/utils/common/constants.js.map +1 -0
- package/utils/common/index.d.ts +15 -0
- package/utils/common/index.js +26 -0
- package/utils/common/index.js.map +1 -0
- package/utils/common/package.json +6 -0
- package/utils/cookies/constants.d.ts +7 -0
- package/utils/cookies/constants.js +8 -0
- package/utils/cookies/constants.js.map +1 -0
- package/utils/cookies/helpers.d.ts +25 -0
- package/utils/cookies/helpers.js +53 -0
- package/utils/cookies/helpers.js.map +1 -0
- package/utils/cookies/index.d.ts +45 -0
- package/utils/cookies/index.js +232 -0
- package/utils/cookies/index.js.map +1 -0
- package/utils/cookies/package.json +6 -0
- package/utils/cookies/serializer.d.ts +22 -0
- package/utils/cookies/serializer.js +154 -0
- package/utils/cookies/serializer.js.map +1 -0
- package/utils/cookies/types.d.ts +31 -0
- package/utils/cookies/types.js +2 -0
- package/utils/cookies/types.js.map +1 -0
- package/utils/createSession/index.d.ts +2 -0
- package/utils/createSession/index.js +44 -0
- package/utils/createSession/index.js.map +1 -0
- package/utils/createSession/package.json +6 -0
- package/utils/encryption/index.d.ts +3 -0
- package/utils/encryption/index.js +29 -0
- package/utils/encryption/index.js.map +1 -0
- package/utils/encryption/package.json +6 -0
- package/utils/encryption-edge/index.d.ts +3 -0
- package/utils/encryption-edge/index.js +29 -0
- package/utils/encryption-edge/index.js.map +1 -0
- package/utils/encryption-edge/package.json +6 -0
- package/utils/errors/FronteggEnvNotFound.d.ts +3 -0
- package/utils/errors/FronteggEnvNotFound.js +8 -0
- package/utils/errors/FronteggEnvNotFound.js.map +1 -0
- package/utils/errors/InvalidFronteggEnv.d.ts +3 -0
- package/utils/errors/InvalidFronteggEnv.js +8 -0
- package/utils/errors/InvalidFronteggEnv.js.map +1 -0
- package/utils/errors/index.d.ts +2 -0
- package/utils/errors/index.js +3 -0
- package/utils/errors/index.js.map +1 -0
- package/utils/errors/package.json +6 -0
- package/utils/fetchUserData/index.d.ts +7 -0
- package/utils/fetchUserData/index.js +49 -0
- package/utils/fetchUserData/index.js.map +1 -0
- package/utils/fetchUserData/package.json +6 -0
- package/utils/fronteggLogger/constants.d.ts +13 -0
- package/utils/fronteggLogger/constants.js +20 -0
- package/utils/fronteggLogger/constants.js.map +1 -0
- package/utils/fronteggLogger/index.d.ts +17 -0
- package/utils/fronteggLogger/index.js +61 -0
- package/utils/fronteggLogger/index.js.map +1 -0
- package/utils/fronteggLogger/package.json +6 -0
- package/{common/client/createOrGetFronteggApp.d.ts → utils/initializeFronteggApp/index.d.ts} +11 -11
- package/utils/initializeFronteggApp/index.js +100 -0
- package/utils/initializeFronteggApp/index.js.map +1 -0
- package/utils/initializeFronteggApp/package.json +6 -0
- package/utils/jwt/index.d.ts +22 -0
- package/utils/jwt/index.js +53 -0
- package/utils/jwt/index.js.map +1 -0
- package/utils/jwt/package.json +6 -0
- package/utils/refreshAccessToken/helpers.d.ts +16 -0
- package/utils/refreshAccessToken/helpers.js +69 -0
- package/utils/refreshAccessToken/helpers.js.map +1 -0
- package/utils/refreshAccessToken/index.d.ts +9 -0
- package/utils/refreshAccessToken/index.js +88 -0
- package/utils/refreshAccessToken/index.js.map +1 -0
- package/utils/refreshAccessToken/package.json +6 -0
- package/utils/routing/index.d.ts +5 -0
- package/utils/routing/index.js +23 -0
- package/utils/routing/index.js.map +1 -0
- package/utils/routing/package.json +6 -0
- package/utils/useOnRedirectTo/index.d.ts +5 -0
- package/utils/useOnRedirectTo/index.js +21 -0
- package/utils/useOnRedirectTo/index.js.map +1 -0
- package/utils/useOnRedirectTo/package.json +6 -0
- package/CookieManager-e50dc144.js +0 -322
- package/CookieManager-e50dc144.js.map +0 -1
- package/FronteggClientProviderNext13-b3c1e7a0.js +0 -158
- package/FronteggClientProviderNext13-b3c1e7a0.js.map +0 -1
- package/FronteggMiddleware.d.ts +0 -15
- package/FronteggProvider.d.ts +0 -3
- package/api-25516652.js +0 -58
- package/api-25516652.js.map +0 -1
- package/client/FronteggClientProviderNext13.d.ts +0 -3
- package/client/index.d.ts +0 -2
- package/client/index.js +0 -64
- package/client/index.js.map +0 -1
- package/common/CookieManager.d.ts +0 -41
- package/common/FronteggConfig.d.ts +0 -31
- package/common/api.d.ts +0 -3
- package/common/client/ExpireInListener.d.ts +0 -2
- package/common/client/hooks/index.d.ts +0 -1
- package/common/client/hooks/useRequestAuthorizeSSR.d.ts +0 -5
- package/common/client/index.d.ts +0 -4
- package/common/consts.d.ts +0 -6
- package/common/createGetSession.d.ts +0 -7
- package/common/utils.d.ts +0 -1
- package/createGetSession-2e1e4506.js +0 -50
- package/createGetSession-2e1e4506.js.map +0 -1
- package/helpers-dac37998.js +0 -88
- package/helpers-dac37998.js.map +0 -1
- package/refreshToken.d.ts +0 -3
- package/server/FronteggProviderNext13.d.ts +0 -3
- package/server/getSessionNext13.d.ts +0 -4
- package/server/index.d.ts +0 -2
- package/server/index.js +0 -84
- package/server/index.js.map +0 -1
- package/withFronteggApp.d.ts +0 -11
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const FRONTEGG_AFTER_AUTH_REDIRECT_URL = "FRONTEGG_AFTER_AUTH_REDIRECT_URL";
|
|
2
|
+
/**
|
|
3
|
+
* Matches if val contains an invalid field-vchar
|
|
4
|
+
* field-value = *( field-content / obs-fold )
|
|
5
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
6
|
+
* field-vchar = VCHAR / obs-text
|
|
7
|
+
*
|
|
8
|
+
* headerCharRegex have been lifted from
|
|
9
|
+
* https://github.com/nodejs/node/blob/main/lib/_http_common.js
|
|
10
|
+
*/
|
|
11
|
+
export declare const headerCharRegex: RegExp;
|
|
12
|
+
export declare const cookieContentRegExp: RegExp;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const FRONTEGG_AFTER_AUTH_REDIRECT_URL = 'FRONTEGG_AFTER_AUTH_REDIRECT_URL';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Matches if val contains an invalid field-vchar
|
|
5
|
+
* field-value = *( field-content / obs-fold )
|
|
6
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
7
|
+
* field-vchar = VCHAR / obs-text
|
|
8
|
+
*
|
|
9
|
+
* headerCharRegex have been lifted from
|
|
10
|
+
* https://github.com/nodejs/node/blob/main/lib/_http_common.js
|
|
11
|
+
*/
|
|
12
|
+
export const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
|
|
13
|
+
export const cookieContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":["FRONTEGG_AFTER_AUTH_REDIRECT_URL","headerCharRegex","cookieContentRegExp"],"sources":["../../../../../packages/nextjs/src/utils/common/constants.ts"],"sourcesContent":["export const FRONTEGG_AFTER_AUTH_REDIRECT_URL = 'FRONTEGG_AFTER_AUTH_REDIRECT_URL';\n\n/**\n * Matches if val contains an invalid field-vchar\n * field-value = *( field-content / obs-fold )\n * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]\n * field-vchar = VCHAR / obs-text\n *\n * headerCharRegex have been lifted from\n * https://github.com/nodejs/node/blob/main/lib/_http_common.js\n */\nexport const headerCharRegex = /[^\\t\\x20-\\x7e\\x80-\\xff]/;\nexport const cookieContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\n"],"mappings":"AAAA,OAAO,MAAMA,gCAAgC,GAAG,kCAAkC;;AAElF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAG,yBAAyB;AACxD,OAAO,MAAMC,mBAAmB,GAAG,uCAAuC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a string into chunks of a specified size.
|
|
3
|
+
* @param {string} str - The string to be chunked.
|
|
4
|
+
* @param {number} chunkSize - The maximum size of each chunk.
|
|
5
|
+
* @returns {string[]} An array of chunks of the specified size.
|
|
6
|
+
*/
|
|
7
|
+
declare function chunkString(str: string, chunkSize: number): string[];
|
|
8
|
+
export { chunkString };
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the time until an expiration time based on the current time.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} exp - The expiration time in seconds since the Unix epoch.
|
|
13
|
+
* @returns {number} The time until expiration in seconds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const calculateExpiresInFromExp: (exp: number) => number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a string into chunks of a specified size.
|
|
3
|
+
* @param {string} str - The string to be chunked.
|
|
4
|
+
* @param {number} chunkSize - The maximum size of each chunk.
|
|
5
|
+
* @returns {string[]} An array of chunks of the specified size.
|
|
6
|
+
*/
|
|
7
|
+
function chunkString(str, chunkSize) {
|
|
8
|
+
const numChunks = Math.ceil(str.length / chunkSize);
|
|
9
|
+
const chunks = [];
|
|
10
|
+
for (let i = 0; i < numChunks; i++) {
|
|
11
|
+
const start = i * chunkSize;
|
|
12
|
+
const end = start + chunkSize;
|
|
13
|
+
chunks.push(str.substring(start, end < str.length ? end : str.length));
|
|
14
|
+
}
|
|
15
|
+
return chunks;
|
|
16
|
+
}
|
|
17
|
+
export { chunkString };
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Calculates the time until an expiration time based on the current time.
|
|
21
|
+
*
|
|
22
|
+
* @param {number} exp - The expiration time in seconds since the Unix epoch.
|
|
23
|
+
* @returns {number} The time until expiration in seconds.
|
|
24
|
+
*/
|
|
25
|
+
export const calculateExpiresInFromExp = exp => Math.floor((exp * 1000 - Date.now()) / 1000);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["chunkString","str","chunkSize","numChunks","Math","ceil","length","chunks","i","start","end","push","substring","calculateExpiresInFromExp","exp","floor","Date","now"],"sources":["../../../../../packages/nextjs/src/utils/common/index.ts"],"sourcesContent":["/**\n * Splits a string into chunks of a specified size.\n * @param {string} str - The string to be chunked.\n * @param {number} chunkSize - The maximum size of each chunk.\n * @returns {string[]} An array of chunks of the specified size.\n */\nfunction chunkString(str: string, chunkSize: number) {\n const numChunks = Math.ceil(str.length / chunkSize);\n const chunks: string[] = [];\n for (let i = 0; i < numChunks; i++) {\n const start = i * chunkSize;\n const end = start + chunkSize;\n chunks.push(str.substring(start, end < str.length ? end : str.length));\n }\n return chunks;\n}\n\nexport { chunkString };\n\n/**\n * Calculates the time until an expiration time based on the current time.\n *\n * @param {number} exp - The expiration time in seconds since the Unix epoch.\n * @returns {number} The time until expiration in seconds.\n */\nexport const calculateExpiresInFromExp = (exp: number) => Math.floor((exp * 1000 - Date.now()) / 1000);\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAW,CAACC,GAAW,EAAEC,SAAiB,EAAE;EACnD,MAAMC,SAAS,GAAGC,IAAI,CAACC,IAAI,CAACJ,GAAG,CAACK,MAAM,GAAGJ,SAAS,CAAC;EACnD,MAAMK,MAAgB,GAAG,EAAE;EAC3B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,SAAS,EAAEK,CAAC,EAAE,EAAE;IAClC,MAAMC,KAAK,GAAGD,CAAC,GAAGN,SAAS;IAC3B,MAAMQ,GAAG,GAAGD,KAAK,GAAGP,SAAS;IAC7BK,MAAM,CAACI,IAAI,CAACV,GAAG,CAACW,SAAS,CAACH,KAAK,EAAEC,GAAG,GAAGT,GAAG,CAACK,MAAM,GAAGI,GAAG,GAAGT,GAAG,CAACK,MAAM,CAAC,CAAC;EACxE;EACA,OAAOC,MAAM;AACf;AAEA,SAASP,WAAW;;AAEpB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMa,yBAAyB,GAAIC,GAAW,IAAKV,IAAI,CAACW,KAAK,CAAC,CAACD,GAAG,GAAG,IAAI,GAAGE,IAAI,CAACC,GAAG,EAAE,IAAI,IAAI,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum cookie value length, used to split encrypted session cookie
|
|
3
|
+
* in order to store large jwt as array of cookies
|
|
4
|
+
*
|
|
5
|
+
* The MAX header length is 4092 we picked 4000 as MAX CookieHeader length
|
|
6
|
+
*/
|
|
7
|
+
export const COOKIE_MAX_LENGTH = 4000;
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":["COOKIE_MAX_LENGTH"],"sources":["../../../../../packages/nextjs/src/utils/cookies/constants.ts"],"sourcesContent":["/**\n * Maximum cookie value length, used to split encrypted session cookie\n * in order to store large jwt as array of cookies\n *\n * The MAX header length is 4092 we picked 4000 as MAX CookieHeader length\n */\nexport const COOKIE_MAX_LENGTH = 4000;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,iBAAiB,GAAG,IAAI"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CookieSerializeOptions, RequestType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Return a cookieName with index, used for divided cookies.
|
|
4
|
+
*
|
|
5
|
+
* @param {number} index - The index of the cookie, starts with '1'
|
|
6
|
+
* @param {string} _cookieName - Default is {@link config.cookieName}
|
|
7
|
+
*/
|
|
8
|
+
export declare const getIndexedCookieName: (index: number, _cookieName?: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Split cookie value if value length exceeded the MAX Length of a standard HTTP header.
|
|
11
|
+
* Used to split the session cookie.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} cookieName - Cookie name for serializing
|
|
14
|
+
* @param {string} value - cookie value to split if needed
|
|
15
|
+
* @param {CookieSerializeOptions} options - {@link CookieSerializeOptions} for serializing
|
|
16
|
+
*/
|
|
17
|
+
export declare const splitValueToChunks: (cookieName: string, value: string, options: CookieSerializeOptions) => string[];
|
|
18
|
+
/**
|
|
19
|
+
* Receive incoming http request, and extract the cookie header.
|
|
20
|
+
* @return cookie as string if exists, else empty string
|
|
21
|
+
*
|
|
22
|
+
* @param {RequestType} request - Incoming HTTP Request
|
|
23
|
+
*/
|
|
24
|
+
export declare const getCookieHeader: (request: RequestType) => string;
|
|
25
|
+
export declare const getRefreshTokenCookieNameVariants: () => string[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import cookieSerializer from './serializer';
|
|
2
|
+
import { COOKIE_MAX_LENGTH } from './constants';
|
|
3
|
+
import { chunkString } from '../common';
|
|
4
|
+
import config from '../../config';
|
|
5
|
+
/**
|
|
6
|
+
* Return a cookieName with index, used for divided cookies.
|
|
7
|
+
*
|
|
8
|
+
* @param {number} index - The index of the cookie, starts with '1'
|
|
9
|
+
* @param {string} _cookieName - Default is {@link config.cookieName}
|
|
10
|
+
*/
|
|
11
|
+
export const getIndexedCookieName = (index, _cookieName) => {
|
|
12
|
+
const cookieName = _cookieName != null ? _cookieName : config.cookieName;
|
|
13
|
+
return `${cookieName}-${index}`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Split cookie value if value length exceeded the MAX Length of a standard HTTP header.
|
|
18
|
+
* Used to split the session cookie.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} cookieName - Cookie name for serializing
|
|
21
|
+
* @param {string} value - cookie value to split if needed
|
|
22
|
+
* @param {CookieSerializeOptions} options - {@link CookieSerializeOptions} for serializing
|
|
23
|
+
*/
|
|
24
|
+
export const splitValueToChunks = (cookieName, value, options) => {
|
|
25
|
+
const cookieOptionLength = cookieSerializer.serialize(getIndexedCookieName(1, cookieName), '', options).length;
|
|
26
|
+
const chunkSize = COOKIE_MAX_LENGTH - cookieOptionLength - 1;
|
|
27
|
+
const valueChunks = chunkString(value, chunkSize);
|
|
28
|
+
return valueChunks.map((chunk, index) => {
|
|
29
|
+
const indexedCookieName = getIndexedCookieName(index + 1, cookieName);
|
|
30
|
+
return cookieSerializer.serialize(indexedCookieName, chunk, options) + ';';
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Receive incoming http request, and extract the cookie header.
|
|
36
|
+
* @return cookie as string if exists, else empty string
|
|
37
|
+
*
|
|
38
|
+
* @param {RequestType} request - Incoming HTTP Request
|
|
39
|
+
*/
|
|
40
|
+
export const getCookieHeader = request => {
|
|
41
|
+
let cookieHeader;
|
|
42
|
+
if ('credentials' in request) {
|
|
43
|
+
cookieHeader = request.headers.get('cookie');
|
|
44
|
+
} else {
|
|
45
|
+
cookieHeader = request.headers.cookie;
|
|
46
|
+
}
|
|
47
|
+
if (!cookieHeader) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
return cookieHeader;
|
|
51
|
+
};
|
|
52
|
+
export const getRefreshTokenCookieNameVariants = () => [`fe_refresh_${config.clientId}`, `fe_refresh_${config.clientId.replace('-', '')}`, `fe_refresh_${config.clientId.replace(/-/g, '')}`];
|
|
53
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","names":["cookieSerializer","COOKIE_MAX_LENGTH","chunkString","config","getIndexedCookieName","index","_cookieName","cookieName","splitValueToChunks","value","options","cookieOptionLength","serialize","length","chunkSize","valueChunks","map","chunk","indexedCookieName","getCookieHeader","request","cookieHeader","headers","get","cookie","getRefreshTokenCookieNameVariants","clientId","replace"],"sources":["../../../../../packages/nextjs/src/utils/cookies/helpers.ts"],"sourcesContent":["import cookieSerializer from './serializer';\nimport { COOKIE_MAX_LENGTH } from './constants';\nimport { chunkString } from '../common';\nimport config from '../../config';\nimport { CookieSerializeOptions, RequestType } from './types';\n\n/**\n * Return a cookieName with index, used for divided cookies.\n *\n * @param {number} index - The index of the cookie, starts with '1'\n * @param {string} _cookieName - Default is {@link config.cookieName}\n */\nexport const getIndexedCookieName = (index: number, _cookieName?: string) => {\n const cookieName = _cookieName ?? config.cookieName;\n return `${cookieName}-${index}`;\n};\n\n/**\n * Split cookie value if value length exceeded the MAX Length of a standard HTTP header.\n * Used to split the session cookie.\n *\n * @param {string} cookieName - Cookie name for serializing\n * @param {string} value - cookie value to split if needed\n * @param {CookieSerializeOptions} options - {@link CookieSerializeOptions} for serializing\n */\nexport const splitValueToChunks = (cookieName: string, value: string, options: CookieSerializeOptions): string[] => {\n const cookieOptionLength = cookieSerializer.serialize(getIndexedCookieName(1, cookieName), '', options).length;\n const chunkSize = COOKIE_MAX_LENGTH - cookieOptionLength - 1;\n\n const valueChunks = chunkString(value, chunkSize);\n\n return valueChunks.map((chunk, index) => {\n const indexedCookieName = getIndexedCookieName(index + 1, cookieName);\n return cookieSerializer.serialize(indexedCookieName, chunk, options) + ';';\n });\n};\n\n/**\n * Receive incoming http request, and extract the cookie header.\n * @return cookie as string if exists, else empty string\n *\n * @param {RequestType} request - Incoming HTTP Request\n */\nexport const getCookieHeader = (request: RequestType): string => {\n let cookieHeader: string | null | undefined;\n if ('credentials' in request) {\n cookieHeader = request.headers.get('cookie');\n } else {\n cookieHeader = request.headers.cookie;\n }\n if (!cookieHeader) {\n return '';\n }\n\n return cookieHeader;\n};\n\nexport const getRefreshTokenCookieNameVariants = () => [\n `fe_refresh_${config.clientId}`,\n `fe_refresh_${config.clientId.replace('-', '')}`,\n `fe_refresh_${config.clientId.replace(/-/g, '')}`,\n];\n"],"mappings":"AAAA,OAAOA,gBAAgB,MAAM,cAAc;AAC3C,SAASC,iBA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ACE,MAAM;EACvC;EACA,IAAI,CAACH,YAAY,EAAE;IACjB,OAAO,EAAE;EACX;EAEA,OAAOA,YAAY;AACrB,CAAC;AAED,OAAO,MAAMI,iCAAiC,GAAG,MAAM,CACpD,cAAatB,MAAM,CAACuB,QAAS,EAAC,EAC9B,cAAavB,MAAM,CAACuB,QAAQ,CAACC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAE,EAAC,EAC/C,cAAaxB,MAAM,CAACuB,QAAQ,CAACC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAE,EAAC,CAClD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { RequestCookie } from 'next/dist/server/web/spec-extension/cookies';
|
|
2
|
+
import { CreateCookieOptions, RemoveCookiesOptions, RequestType } from './types';
|
|
3
|
+
declare class CookieManager {
|
|
4
|
+
getCookieName: (cookieNumber?: number, cookieName?: string) => string;
|
|
5
|
+
get refreshTokenKey(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Validate and create new cookie headers.
|
|
8
|
+
* The default value of `cookieName` is {@link config.cookieName}
|
|
9
|
+
* @param {CreateCookieOptions} options - Create cookie options
|
|
10
|
+
*/
|
|
11
|
+
create(options: CreateCookieOptions): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Receive incoming http request, and extract the cookie header.
|
|
14
|
+
* @return cookie as string if exists, else empty string
|
|
15
|
+
*
|
|
16
|
+
* @param {RequestType} request - Incoming HTTP Request
|
|
17
|
+
*/
|
|
18
|
+
parseCookieHeader(request: RequestType): Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* Loop over cookie headers, extract, parse cookies and merged divided cookies from incoming http request,
|
|
21
|
+
* @return full session cookie headers if exists, else return undefined
|
|
22
|
+
* @param {RequestType} request - Incoming HTTP Request
|
|
23
|
+
*/
|
|
24
|
+
getSessionCookieFromRequest(request?: RequestType): string | undefined;
|
|
25
|
+
parseCookieFromArray(cookies: RequestCookie[]): string | undefined;
|
|
26
|
+
private createEmptySingleCookie;
|
|
27
|
+
createEmptyCookies: (isSecured: boolean, cookieDomain: string, _cookiesToRemove: string[]) => string[];
|
|
28
|
+
private getCookiesToRemove;
|
|
29
|
+
/**
|
|
30
|
+
* Take a list of cookieNames and modify request/response headers
|
|
31
|
+
* to proxy the cookies from Next.js to Frontegg Services and vice-versa
|
|
32
|
+
* @param {string[]} setCookieValue - list of cookies to modify
|
|
33
|
+
* @param {boolean} isSecured - if the running application behind SSL
|
|
34
|
+
*/
|
|
35
|
+
removeCookies({ cookieNames, isSecured, cookieDomain, res, req }: RemoveCookiesOptions): void;
|
|
36
|
+
/**
|
|
37
|
+
* Take a list of cookie headers and modify the Domain / Secure / SameSite
|
|
38
|
+
* to proxy the cookies to Frontegg Services and vice-versa
|
|
39
|
+
* @param {string[]} setCookieValue - list of cookies to modify
|
|
40
|
+
* @param {boolean} isSecured - if the running application behind SSL
|
|
41
|
+
*/
|
|
42
|
+
modifySetCookie: (setCookieValue: string[] | undefined, isSecured: boolean) => string[] | undefined;
|
|
43
|
+
}
|
|
44
|
+
declare const _default: CookieManager;
|
|
45
|
+
export default _default;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import cookieSerializer from './serializer';
|
|
2
|
+
import config from '../../config';
|
|
3
|
+
import { COOKIE_MAX_LENGTH } from './constants';
|
|
4
|
+
import { getCookieHeader, getIndexedCookieName, getRefreshTokenCookieNameVariants, splitValueToChunks } from './helpers';
|
|
5
|
+
import fronteggLogger from '../fronteggLogger';
|
|
6
|
+
class CookieManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.getCookieName = (cookieNumber, cookieName = config.cookieName) => cookieNumber ? getIndexedCookieName(cookieNumber, cookieName) : cookieName;
|
|
9
|
+
this.createEmptySingleCookie = (cookieName, isSecured, cookieDomain) => {
|
|
10
|
+
return this.create({
|
|
11
|
+
cookieName,
|
|
12
|
+
value: '',
|
|
13
|
+
expires: new Date(),
|
|
14
|
+
secure: isSecured,
|
|
15
|
+
domain: cookieDomain,
|
|
16
|
+
silent: true
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
this.createEmptyCookies = (isSecured, cookieDomain, _cookiesToRemove) => {
|
|
20
|
+
const allEmptyCookies = [];
|
|
21
|
+
const refreshTokenVariants = getRefreshTokenCookieNameVariants();
|
|
22
|
+
const cookiesToRemove = [..._cookiesToRemove, ...refreshTokenVariants];
|
|
23
|
+
cookiesToRemove.forEach(name => {
|
|
24
|
+
allEmptyCookies.push(...this.createEmptySingleCookie(name, isSecured, cookieDomain));
|
|
25
|
+
});
|
|
26
|
+
return allEmptyCookies;
|
|
27
|
+
};
|
|
28
|
+
this.getCookiesToRemove = request => {
|
|
29
|
+
const logger = fronteggLogger.child({
|
|
30
|
+
tag: 'getCookiesToRemove'
|
|
31
|
+
});
|
|
32
|
+
if (!request) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
logger.info('extract cookie from request headers');
|
|
37
|
+
const cookieStr = getCookieHeader(request);
|
|
38
|
+
const cookies = cookieStr && cookieSerializer.parse(cookieStr);
|
|
39
|
+
if (!cookies) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
let cookieNumber = 1;
|
|
43
|
+
const cookieToRemove = [];
|
|
44
|
+
while (cookies[this.getCookieName(cookieNumber)]) {
|
|
45
|
+
cookieToRemove.push(this.getCookieName(cookieNumber));
|
|
46
|
+
cookieNumber++;
|
|
47
|
+
}
|
|
48
|
+
logger.info(`number of cookies to remove: ${cookieToRemove.length}`);
|
|
49
|
+
return cookieToRemove;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
logger.error(e);
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
this.modifySetCookie = (setCookieValue, isSecured) => {
|
|
56
|
+
const logger = fronteggLogger.child({
|
|
57
|
+
tag: 'CookieManager.modifySetCookie'
|
|
58
|
+
});
|
|
59
|
+
if (!setCookieValue || setCookieValue.length === 0) {
|
|
60
|
+
logger.info(`No headers to modify`);
|
|
61
|
+
return setCookieValue;
|
|
62
|
+
}
|
|
63
|
+
logger.info(`modifying cookie headers (count: ${setCookieValue.length})`);
|
|
64
|
+
return setCookieValue.map(c => {
|
|
65
|
+
let cookie = c.split('; ');
|
|
66
|
+
logger.debug(`modifying cookie ${cookie[0]}, isSecured: ${isSecured}`);
|
|
67
|
+
if (!isSecured) {
|
|
68
|
+
cookie = cookie.filter(property => property !== 'Secure' && property !== 'SameSite=None');
|
|
69
|
+
}
|
|
70
|
+
return cookie.map(property => {
|
|
71
|
+
if (property.toLowerCase() === `domain=${config.baseUrlHost}`) {
|
|
72
|
+
return `Domain=${config.cookieDomain}`;
|
|
73
|
+
}
|
|
74
|
+
return property;
|
|
75
|
+
}).join(';') + ';';
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
get refreshTokenKey() {
|
|
80
|
+
return `fe_refresh_${config.clientId}`.replace(/-/g, '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validate and create new cookie headers.
|
|
85
|
+
* The default value of `cookieName` is {@link config.cookieName}
|
|
86
|
+
* @param {CreateCookieOptions} options - Create cookie options
|
|
87
|
+
*/
|
|
88
|
+
create(options) {
|
|
89
|
+
var _options$cookieName, _options$httpOnly, _options$domain, _options$path;
|
|
90
|
+
const logger = fronteggLogger.child({
|
|
91
|
+
tag: 'CookieManager.create',
|
|
92
|
+
level: options.silent ? 'error' : undefined
|
|
93
|
+
});
|
|
94
|
+
const cookieName = (_options$cookieName = options.cookieName) != null ? _options$cookieName : config.cookieName;
|
|
95
|
+
const cookieValue = options.value;
|
|
96
|
+
logger.info(`Creating new cookie for '${cookieName}'`);
|
|
97
|
+
const serializeOptions = {
|
|
98
|
+
expires: options.expires,
|
|
99
|
+
httpOnly: (_options$httpOnly = options.httpOnly) != null ? _options$httpOnly : true,
|
|
100
|
+
domain: (_options$domain = options.domain) != null ? _options$domain : config.cookieDomain,
|
|
101
|
+
path: (_options$path = options.path) != null ? _options$path : '/',
|
|
102
|
+
priority: 'high'
|
|
103
|
+
};
|
|
104
|
+
if (options.secure) {
|
|
105
|
+
logger.debug(`Set cookie '${cookieName}' as secure`);
|
|
106
|
+
serializeOptions.secure = options.secure;
|
|
107
|
+
serializeOptions.sameSite = 'none';
|
|
108
|
+
}
|
|
109
|
+
const serializedCookie = cookieSerializer.serialize(cookieName, cookieValue, serializeOptions);
|
|
110
|
+
if (serializedCookie.length <= COOKIE_MAX_LENGTH) {
|
|
111
|
+
logger.info(`Successfully create a cookie header, '${cookieName}'`);
|
|
112
|
+
return [serializedCookie];
|
|
113
|
+
} else {
|
|
114
|
+
logger.debug('Going to split cookie into chunks');
|
|
115
|
+
/** Create chunked cookie headers and store value as array of headers */
|
|
116
|
+
const cookies = splitValueToChunks(cookieName, cookieValue, serializeOptions);
|
|
117
|
+
logger.info(`Successfully create chunked cookie headers, '${cookieName}' (count: ${cookies.length})`);
|
|
118
|
+
return cookies;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Receive incoming http request, and extract the cookie header.
|
|
124
|
+
* @return cookie as string if exists, else empty string
|
|
125
|
+
*
|
|
126
|
+
* @param {RequestType} request - Incoming HTTP Request
|
|
127
|
+
*/
|
|
128
|
+
parseCookieHeader(request) {
|
|
129
|
+
const logger = fronteggLogger.child({
|
|
130
|
+
tag: 'CookieManager.parseCookieHeader'
|
|
131
|
+
});
|
|
132
|
+
logger.info('Going to extract all cookies header from request');
|
|
133
|
+
const cookieHeader = getCookieHeader(request);
|
|
134
|
+
logger.info('Parsing cookie header to map');
|
|
135
|
+
return cookieSerializer.parse(cookieHeader);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Loop over cookie headers, extract, parse cookies and merged divided cookies from incoming http request,
|
|
140
|
+
* @return full session cookie headers if exists, else return undefined
|
|
141
|
+
* @param {RequestType} request - Incoming HTTP Request
|
|
142
|
+
*/
|
|
143
|
+
getSessionCookieFromRequest(request) {
|
|
144
|
+
const logger = fronteggLogger.child({
|
|
145
|
+
tag: 'CookieManager.getSessionCookieFromRequest'
|
|
146
|
+
});
|
|
147
|
+
logger.info('Going to extract session cookies header from request');
|
|
148
|
+
if (!request) {
|
|
149
|
+
logger.info(`'request' argument is null, Cookie header not found`);
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
logger.debug('Getting cookie header');
|
|
153
|
+
const cookieStr = getCookieHeader(request);
|
|
154
|
+
logger.debug('Parsing cookie header string');
|
|
155
|
+
const cookies = cookieSerializer.parse(cookieStr);
|
|
156
|
+
logger.debug('Loop over session cookie headers');
|
|
157
|
+
let i = 1;
|
|
158
|
+
let sessionCookies = '';
|
|
159
|
+
let sessionCookieChunk = cookies[this.getCookieName()];
|
|
160
|
+
if (sessionCookieChunk === undefined) {
|
|
161
|
+
do {
|
|
162
|
+
sessionCookieChunk = cookies[getIndexedCookieName(i++)];
|
|
163
|
+
if (sessionCookieChunk) {
|
|
164
|
+
sessionCookies += sessionCookieChunk;
|
|
165
|
+
}
|
|
166
|
+
} while (sessionCookieChunk);
|
|
167
|
+
}
|
|
168
|
+
if (sessionCookies.length === 0) {
|
|
169
|
+
logger.info('Session cookie NOT found');
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
logger.info(`Session cookie found, (count: ${sessionCookies.length})`);
|
|
173
|
+
return sessionCookies;
|
|
174
|
+
}
|
|
175
|
+
parseCookieFromArray(cookies) {
|
|
176
|
+
const logger = fronteggLogger.child({
|
|
177
|
+
tag: 'CookieManager.parseCookieFromArray'
|
|
178
|
+
});
|
|
179
|
+
const cookieChunks = cookies.filter(c => c.name.includes(this.getCookieName()));
|
|
180
|
+
logger.info('Parsing session cookie from RequestCookie for Next.JS 13+');
|
|
181
|
+
if (!cookieChunks || cookieChunks.length === 0) {
|
|
182
|
+
logger.info(`No session cookies found`);
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
logger.debug(`Found ${cookieChunks.length} chunks`);
|
|
186
|
+
cookieChunks.sort((a, b) => {
|
|
187
|
+
const firstCookieNumber = parseInt(a.name.slice(-1));
|
|
188
|
+
const secondCookieNumber = parseInt(b.name.slice(-1));
|
|
189
|
+
return firstCookieNumber > secondCookieNumber ? 1 : -1;
|
|
190
|
+
});
|
|
191
|
+
logger.info(`Concatenate session cookies chunks`);
|
|
192
|
+
return cookieChunks.map(c => c.value).join('');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Take a list of cookieNames and modify request/response headers
|
|
196
|
+
* to proxy the cookies from Next.js to Frontegg Services and vice-versa
|
|
197
|
+
* @param {string[]} setCookieValue - list of cookies to modify
|
|
198
|
+
* @param {boolean} isSecured - if the running application behind SSL
|
|
199
|
+
*/
|
|
200
|
+
removeCookies({
|
|
201
|
+
cookieNames,
|
|
202
|
+
isSecured,
|
|
203
|
+
cookieDomain,
|
|
204
|
+
res,
|
|
205
|
+
req
|
|
206
|
+
}) {
|
|
207
|
+
var _ref;
|
|
208
|
+
const logger = fronteggLogger.child({
|
|
209
|
+
tag: 'CookieManager.removeCookies'
|
|
210
|
+
});
|
|
211
|
+
logger.debug('Setting empty cookie headers remove cookies from client side');
|
|
212
|
+
const cookiesToRemove = this.getCookiesToRemove(req);
|
|
213
|
+
const cookieValue = this.createEmptyCookies(isSecured, cookieDomain, cookieNames != null ? cookieNames : cookiesToRemove);
|
|
214
|
+
let existingSetCookie = (_ref = res.getHeader('set-cookie')) != null ? _ref : [];
|
|
215
|
+
if (typeof existingSetCookie === 'string') {
|
|
216
|
+
existingSetCookie = [existingSetCookie];
|
|
217
|
+
}
|
|
218
|
+
const setCookieHeaders = [...existingSetCookie, ...cookieValue];
|
|
219
|
+
logger.debug(`removing headers (count: ${setCookieHeaders.length})`);
|
|
220
|
+
res.setHeader('set-cookie', setCookieHeaders);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Take a list of cookie headers and modify the Domain / Secure / SameSite
|
|
225
|
+
* to proxy the cookies to Frontegg Services and vice-versa
|
|
226
|
+
* @param {string[]} setCookieValue - list of cookies to modify
|
|
227
|
+
* @param {boolean} isSecured - if the running application behind SSL
|
|
228
|
+
*/
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export default new CookieManager();
|
|
232
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["cookieSerializer","config","COOKIE_MAX_LENGTH","getCookieHeader","getIndexedCookieName","getRefreshTokenCookieNameVariants","splitValueToChunks","fronteggLogger","CookieManager","getCookieName","cookieNumber","cookieName","createEmptySingleCookie","isSecured","cookieDomain","create","value","expires","Date","secure","domain","silent","createEmptyCookies","_cookiesToRemove","allEmptyCookies","refreshTokenVariants","cookiesToRemove","forEach","name","push","getCookiesToRemove","request","logger","child","tag","info","cookieStr","cookies","parse","cookieToRemove","length","e","error","modifySetCookie","setCookieValue","map","c","cookie","split","debug","filter","property","toLowerCase","baseUrlHost","join","refreshTokenKey","clientId","replace","options","level","undefined","cookieValue","serializeOptions","httpOnly","path","priority","sameSite","serializedCookie","serialize","parseCookieHeader","cookieHeader","getSessionCookieFromRequest","i","sessionCookies","sessionCookieChunk","parseCookieFromArray","cookieChunks","includes","sort","a","b","firstCookieNumber","parseInt","slice","secondCookieNumber","removeCookies","cookieNames","res","req","existingSetCookie","getHeader","setCookieHeaders","setHeader"],"sources":["../../../../../packages/nextjs/src/utils/cookies/index.ts"],"sourcesContent":["import cookieSerializer from './serializer';\nimport type { RequestCookie } from 'next/dist/server/web/spec-extension/cookies';\nimport config from '../../config';\nimport { CookieSerializeOptions, CreateCookieOptions, RemoveCookiesOptions, RequestType } from './types';\nimport { COOKIE_MAX_LENGTH } from './constants';\n\nimport {\n getCookieHeader,\n getIndexedCookieName,\n getRefreshTokenCookieNameVariants,\n splitValueToChunks,\n} from './helpers';\nimport fronteggLogger from '../fronteggLogger';\n\nclass CookieManager {\n getCookieName = (cookieNumber?: number, cookieName = config.cookieName) =>\n cookieNumber ? getIndexedCookieName(cookieNumber, cookieName) : cookieName;\n\n get refreshTokenKey(): string {\n return `fe_refresh_${config.clientId}`.replace(/-/g, '');\n }\n\n /**\n * Validate and create new cookie headers.\n * The default value of `cookieName` is {@link config.cookieName}\n * @param {CreateCookieOptions} options - Create cookie options\n */\n create(options: CreateCookieOptions): string[] {\n const logger = fronteggLogger.child({ tag: 'CookieManager.create', level: options.silent ? 'error' : undefined });\n const cookieName = options.cookieName ?? config.cookieName;\n const cookieValue = options.value;\n logger.info(`Creating new cookie for '${cookieName}'`);\n\n const serializeOptions: CookieSerializeOptions = {\n expires: options.expires,\n httpOnly: options.httpOnly ?? true,\n domain: options.domain ?? config.cookieDomain,\n path: options.path ?? '/',\n priority: 'high',\n };\n\n if (options.secure) {\n logger.debug(`Set cookie '${cookieName}' as secure`);\n serializeOptions.secure = options.secure;\n serializeOptions.sameSite = 'none';\n }\n\n const serializedCookie = cookieSerializer.serialize(cookieName, cookieValue, serializeOptions);\n\n if (serializedCookie.length <= COOKIE_MAX_LENGTH) {\n logger.info(`Successfully create a cookie header, '${cookieName}'`);\n return [serializedCookie];\n } else {\n logger.debug('Going to split cookie into chunks');\n /** Create chunked cookie headers and store value as array of headers */\n const cookies = splitValueToChunks(cookieName, cookieValue, serializeOptions);\n logger.info(`Successfully create chunked cookie headers, '${cookieName}' (count: ${cookies.length})`);\n return cookies;\n }\n }\n\n /**\n * Receive incoming http request, and extract the cookie header.\n * @return cookie as string if exists, else empty string\n *\n * @param {RequestType} request - Incoming HTTP Request\n */\n parseCookieHeader(request: RequestType): Record<string, string> {\n const logger = fronteggLogger.child({ tag: 'CookieManager.parseCookieHeader' });\n\n logger.info('Going to extract all cookies header from request');\n const cookieHeader = getCookieHeader(request);\n logger.info('Parsing cookie header to map');\n return cookieSerializer.parse(cookieHeader);\n }\n\n /**\n * Loop over cookie headers, extract, parse cookies and merged divided cookies from incoming http request,\n * @return full session cookie headers if exists, else return undefined\n * @param {RequestType} request - Incoming HTTP Request\n */\n getSessionCookieFromRequest(request?: RequestType): string | undefined {\n const logger = fronteggLogger.child({ tag: 'CookieManager.getSessionCookieFromRequest' });\n logger.info('Going to extract session cookies header from request');\n\n if (!request) {\n logger.info(`'request' argument is null, Cookie header not found`);\n return undefined;\n }\n\n logger.debug('Getting cookie header');\n const cookieStr = getCookieHeader(request);\n\n logger.debug('Parsing cookie header string');\n const cookies = cookieSerializer.parse(cookieStr);\n\n logger.debug('Loop over session cookie headers');\n let i = 1;\n let sessionCookies = '';\n let sessionCookieChunk: string | undefined = cookies[this.getCookieName()];\n if (sessionCookieChunk === undefined) {\n do {\n sessionCookieChunk = cookies[getIndexedCookieName(i++)];\n if (sessionCookieChunk) {\n sessionCookies += sessionCookieChunk;\n }\n } while (sessionCookieChunk);\n }\n\n if (sessionCookies.length === 0) {\n logger.info('Session cookie NOT found');\n return undefined;\n }\n\n logger.info(`Session cookie found, (count: ${sessionCookies.length})`);\n return sessionCookies;\n }\n\n parseCookieFromArray(cookies: RequestCookie[]): string | undefined {\n const logger = fronteggLogger.child({ tag: 'CookieManager.parseCookieFromArray' });\n const cookieChunks = cookies.filter((c) => c.name.includes(this.getCookieName()));\n logger.info('Parsing session cookie from RequestCookie for Next.JS 13+');\n\n if (!cookieChunks || cookieChunks.length === 0) {\n logger.info(`No session cookies found`);\n return undefined;\n }\n logger.debug(`Found ${cookieChunks.length} chunks`);\n cookieChunks.sort((a, b) => {\n const firstCookieNumber = parseInt(a.name.slice(-1));\n const secondCookieNumber = parseInt(b.name.slice(-1));\n return firstCookieNumber > secondCookieNumber ? 1 : -1;\n });\n\n logger.info(`Concatenate session cookies chunks`);\n return cookieChunks.map((c) => c.value).join('');\n }\n\n private createEmptySingleCookie = (cookieName: string, isSecured: boolean, cookieDomain: string) => {\n return this.create({\n cookieName,\n value: '',\n expires: new Date(),\n secure: isSecured,\n domain: cookieDomain,\n silent: true,\n });\n };\n\n createEmptyCookies = (isSecured: boolean, cookieDomain: string, _cookiesToRemove: string[]): string[] => {\n const allEmptyCookies: string[] = [];\n\n const refreshTokenVariants = getRefreshTokenCookieNameVariants();\n const cookiesToRemove = [..._cookiesToRemove, ...refreshTokenVariants];\n\n cookiesToRemove.forEach((name: string) => {\n allEmptyCookies.push(...this.createEmptySingleCookie(name, isSecured, cookieDomain));\n });\n\n return allEmptyCookies;\n };\n\n private getCookiesToRemove = (request?: RequestType): string[] => {\n const logger = fronteggLogger.child({ tag: 'getCookiesToRemove' });\n if (!request) {\n return [];\n }\n try {\n logger.info('extract cookie from request headers');\n const cookieStr = getCookieHeader(request);\n const cookies = cookieStr && cookieSerializer.parse(cookieStr);\n if (!cookies) {\n return [];\n }\n let cookieNumber = 1;\n const cookieToRemove = [];\n while (cookies[this.getCookieName(cookieNumber)]) {\n cookieToRemove.push(this.getCookieName(cookieNumber));\n cookieNumber++;\n }\n logger.info(`number of cookies to remove: ${cookieToRemove.length}`);\n return cookieToRemove;\n } catch (e) {\n logger.error(e);\n return [];\n }\n };\n\n /**\n * Take a list of cookieNames and modify request/response headers\n * to proxy the cookies from Next.js to Frontegg Services and vice-versa\n * @param {string[]} setCookieValue - list of cookies to modify\n * @param {boolean} isSecured - if the running application behind SSL\n */\n removeCookies({ cookieNames, isSecured, cookieDomain, res, req }: RemoveCookiesOptions): void {\n const logger = fronteggLogger.child({ tag: 'CookieManager.removeCookies' });\n logger.debug('Setting empty cookie headers remove cookies from client side');\n const cookiesToRemove = this.getCookiesToRemove(req);\n const cookieValue = this.createEmptyCookies(isSecured, cookieDomain, cookieNames ?? cookiesToRemove);\n let existingSetCookie = (res.getHeader('set-cookie') as string[] | string) ?? [];\n if (typeof existingSetCookie === 'string') {\n existingSetCookie = [existingSetCookie];\n }\n\n const setCookieHeaders = [...existingSetCookie, ...cookieValue];\n logger.debug(`removing headers (count: ${setCookieHeaders.length})`);\n res.setHeader('set-cookie', setCookieHeaders);\n }\n\n /**\n * Take a list of cookie headers and modify the Domain / Secure / SameSite\n * to proxy the cookies to Frontegg Services and vice-versa\n * @param {string[]} setCookieValue - list of cookies to modify\n * @param {boolean} isSecured - if the running application behind SSL\n */\n modifySetCookie = (setCookieValue: string[] | undefined, isSecured: boolean): string[] | undefined => {\n const logger = fronteggLogger.child({ tag: 'CookieManager.modifySetCookie' });\n if (!setCookieValue || setCookieValue.length === 0) {\n logger.info(`No headers to modify`);\n return setCookieValue;\n }\n logger.info(`modifying cookie headers (count: ${setCookieValue.length})`);\n return setCookieValue.map((c) => {\n let cookie = c.split('; ');\n\n logger.debug(`modifying cookie ${cookie[0]}, isSecured: ${isSecured}`);\n if (!isSecured) {\n cookie = cookie.filter((property) => property !== 'Secure' && property !== 'SameSite=None');\n }\n\n return (\n cookie\n .map((property) => {\n if (property.toLowerCase() === `domain=${config.baseUrlHost}`) {\n return `Domain=${config.cookieDomain}`;\n }\n return property;\n })\n .join(';') + ';'\n );\n });\n };\n}\n\nexport default new CookieManager();\n"],"mappings":"AAAA,OAAOA,gBAAgB,MAAM,cAAc;AAE3C,OAAOC,MAAM,MAAM,cAAc;AAEjC,SAASC,iBAAiB,QAAQ,aAAa;AAE/C,SACEC,eAAe,EACfC,oBAAoB,EACpBC,iCAAiC,EACjCC,kBAAkB,QACb,WAAW;AAClB,OAAOC,cAAc,MAAM,mBAAmB;AAE9C,MAAMC,aAAa,CAAC;EAAA;IAAA,KAClBC,aAAa,GAAG,CAACC,YAAqB,EAAEC,UAAU,GAAGV,MAAM,CAACU,UAAU,KACpED,YAAY,GAAGN,oBAAoB,CAACM,YAAY,EAAEC,UAAU,CAAC,GAAGA,UAAU;IAAA,KA0HpEC,uBAAuB,GAAG,CAACD,UAAkB,EAAEE,SAAkB,EAAEC,YAAoB,KAAK;MAClG,OAAO,IAAI,CAACC,MAAM,CAAC;QACjBJ,UAAU;QACVK,KAAK,EAAE,EAAE;QACTC,OAAO,EAAE,IAAIC,IAAI,EAAE;QACnBC,MAAM,EAAEN,S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ACpE+C,GAAG,CAACK,SAAS,CAAC,YAAY,EAAED,gBAAgB,CAAC;EAC/C;;EAEA;AACF;AACA;AACA;AACA;AACA;AA4BA;;AAEA,eAAe,IAAInF,aAAa,EAAE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CookieSerializeOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse an HTTP Cookie header string and returning an object of all cookie
|
|
4
|
+
* name-value pairs.
|
|
5
|
+
*
|
|
6
|
+
* @param str the string representing a `Cookie` header value
|
|
7
|
+
*/
|
|
8
|
+
declare function parse(str: any): Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Serialize a cookie name-value pair into a `Set-Cookie` header string.
|
|
11
|
+
*
|
|
12
|
+
* @param name the name for the cookie
|
|
13
|
+
* @param val value to set the cookie to
|
|
14
|
+
* @param [options] object containing serialization options
|
|
15
|
+
* @throws {TypeError} when `maxAge` options is invalid
|
|
16
|
+
*/
|
|
17
|
+
declare function serialize(name: string, val: string, options?: CookieSerializeOptions): string;
|
|
18
|
+
declare const _default: {
|
|
19
|
+
serialize: typeof serialize;
|
|
20
|
+
parse: typeof parse;
|
|
21
|
+
};
|
|
22
|
+
export default _default;
|