@frontegg/nextjs 8.0.11-alpha.7459694362 → 8.0.11-alpha.7460792997
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/index.js +1 -1
- package/middleware/FronteggApiMiddleware.js +0 -1
- package/middleware/FronteggApiMiddleware.js.map +1 -1
- package/middleware/ProxyRequestCallback.js +2 -1
- package/middleware/ProxyRequestCallback.js.map +1 -1
- package/middleware/ProxyResponseCallback.js +10 -2
- package/middleware/ProxyResponseCallback.js.map +1 -1
- package/package.json +1 -1
- package/sdkVersion.js +1 -1
- package/sdkVersion.js.map +1 -1
package/index.js
CHANGED
|
@@ -19,7 +19,6 @@ const middlewarePromise = (req, res) => new Promise(resolve => {
|
|
|
19
19
|
if (process.env['FRONTEGG_TEST_URL'] && req.url == '/frontegg/middleware-test') {
|
|
20
20
|
options.target = process.env['FRONTEGG_TEST_URL'];
|
|
21
21
|
}
|
|
22
|
-
console.log('this version includes the headers fix');
|
|
23
22
|
_FronteggProxy.FronteggProxy.web(req, res, options);
|
|
24
23
|
});
|
|
25
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FronteggApiMiddleware.js","names":["_FronteggProxy","require","_constants","_helpers","middlewarePromise","req","res","Promise","resolve","_req$url","fronteggUrlPath","rewritePath","url","fronteggPathRewrite","rewriteUrl","fronteggSSOPathRewrite","on","options","target","process","env","
|
|
1
|
+
{"version":3,"file":"FronteggApiMiddleware.js","names":["_FronteggProxy","require","_constants","_helpers","middlewarePromise","req","res","Promise","resolve","_req$url","fronteggUrlPath","rewritePath","url","fronteggPathRewrite","rewriteUrl","fronteggSSOPathRewrite","on","options","target","process","env","FronteggProxy","web","FronteggApiMiddleware"],"sources":["../../../../packages/nextjs/src/middleware/FronteggApiMiddleware.ts"],"sourcesContent":["import type { NextApiRequest, NextApiResponse } from 'next';\nimport { FronteggProxy } from './FronteggProxy';\nimport { fronteggSSOPathRewrite, fronteggPathRewrite } from './constants';\nimport { rewritePath } from './helpers';\n\nconst middlewarePromise = (req: NextApiRequest, res: NextApiResponse) =>\n new Promise<void>((resolve) => {\n const fronteggUrlPath = rewritePath(req.url ?? '/', fronteggPathRewrite);\n const rewriteUrl = rewritePath(fronteggUrlPath ?? '/', fronteggSSOPathRewrite);\n req.url = rewriteUrl;\n res.on('close', () => resolve());\n const options = {\n target: process.env['FRONTEGG_BASE_URL'],\n };\n if (process.env['FRONTEGG_TEST_URL'] && req.url == '/frontegg/middleware-test') {\n options.target = process.env['FRONTEGG_TEST_URL'];\n }\n\n FronteggProxy.web(req, res, options);\n });\n\n/**\n * Next.js HTTP Proxy Middleware\n * @see https://nextjs.org/docs/api-routes/api-middlewares\n * @param {NextApiRequest} req - NextJS api request passed from api routing\n * @param {NextApiResponse} res - NextJS api response passed from api routing\n */\nexport async function FronteggApiMiddleware(req: NextApiRequest, res: NextApiResponse) {\n return await middlewarePromise(req, res);\n}\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,MAAMG,iBAAiB,GAAGA,CAACC,GAAmB,EAAEC,GAAoB,KAClE,IAAIC,OAAO,CAAQC,OAAO,IAAK;EAAA,IAAAC,QAAA;EAC7B,MAAMC,eAAe,GAAG,IAAAC,oBAAW,GAAAF,QAAA,GAACJ,GAAG,CAACO,GAAG,YAAAH,QAAA,GAAI,GAAG,EAAEI,8BAAmB,CAAC;EACxE,MAAMC,UAAU,GAAG,IAAAH,oBAAW,EAACD,eAAe,WAAfA,eAAe,GAAI,GAAG,EAAEK,iCAAsB,CAAC;EAC9EV,GAAG,CAACO,GAAG,GAAGE,UAAU;EACpBR,GAAG,CAACU,EAAE,CAAC,OAAO,EAAE,MAAMR,OAAO,EAAE,CAAC;EAChC,MAAMS,OAAO,GAAG;IACdC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAAC,mBAAmB;EACzC,CAAC;EACD,IAAID,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC,IAAIf,GAAG,CAACO,GAAG,IAAI,2BAA2B,EAAE;IAC9EK,OAAO,CAACC,MAAM,GAAGC,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;EACnD;EAEAC,4BAAa,CAACC,GAAG,CAACjB,GAAG,EAAEC,GAAG,EAAEW,OAAO,CAAC;AACtC,CAAC,CAAC;;AAEJ;AACA;AACA;AACA;AACA;AACA;AACO,eAAeM,qBAAqBA,CAAClB,GAAmB,EAAEC,GAAoB,EAAE;EACrF,OAAO,MAAMF,iBAAiB,CAACC,GAAG,EAAEC,GAAG,CAAC;AAC1C"}
|
|
@@ -44,7 +44,8 @@ const ProxyRequestCallback = (proxyReq, req) => {
|
|
|
44
44
|
proxyReq.setHeader('x-frontegg-middleware', 'true');
|
|
45
45
|
HEADERS_TO_KEEP.forEach(header => {
|
|
46
46
|
const headerValue = req.headers[header];
|
|
47
|
-
|
|
47
|
+
console.log(`headerValue for ${header} is `, headerValue);
|
|
48
|
+
if (headerValue && headerValue != 'undefined') {
|
|
48
49
|
proxyReq.setHeader(header, headerValue);
|
|
49
50
|
}
|
|
50
51
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyRequestCallback.js","names":["_package","_interopRequireDefault","require","_sdkVersion","_config","_cookies","_fronteggLogger","HEADERS_TO_KEEP","HEADERS_TO_REMOVE","logger","fronteggLogger","child","tag","ProxyRequestCallback","proxyReq","req","_req$headers$xFronte","_req$headers$xFronte2","info","url","headers","debug","allCookies","CookieManager","parseCookieHeader","fronteggCookiesNames","Object","keys","filter","cookieName","startsWith","config","join","forEach","setHeader","NextJsPkg","version","sdkVersion","header","headerValue","map","removeHeader","method","body","bodyData","JSON","stringify","Buffer","byteLength","write","e","error","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyRequestCallback.ts"],"sourcesContent":["import NextJsPkg from 'next/package.json';\nimport { ProxyReqCallback } from 'http-proxy';\nimport { ClientRequest } from 'http';\nimport { NextApiRequest } from 'next';\nimport sdkVersion from '../sdkVersion';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport fronteggLogger from '../utils/fronteggLogger';\n\nconst HEADERS_TO_KEEP = ['x-forwarded-for', 'x-original-forwarded-for', 'cf-connecting-ip'];\nconst HEADERS_TO_REMOVE = [\n 'x-forwarded-port',\n 'x-invoke-path',\n 'x-invoke-query',\n 'x-middleware-invoke',\n 'x-middleware-next',\n 'transfer-encoding',\n 'cache-control',\n];\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyRequestCallback' });\n/**\n * Proxy request callback fired on before each request to Frontegg services,\n * to transport frontegg cookies.\n *\n * @param {ClientRequest} proxyReq - Proxy request to be sent\n * @param {NextApiRequest} req - Next.js incoming request\n */\nconst ProxyRequestCallback: ProxyReqCallback<ClientRequest, NextApiRequest> = (proxyReq, req) => {\n try {\n logger.info(`${req.url} | Going to proxy request`);\n logger.info('The original req headers are', { headers: req.headers });\n logger.debug(`${req.url} | parsing request cookies`);\n const allCookies = CookieManager.parseCookieHeader(req);\n logger.debug(`${req.url} | found ${allCookies} cookies`);\n const fronteggCookiesNames = Object.keys(allCookies).filter((cookieName) => {\n return cookieName.startsWith('fe_') && !cookieName.startsWith(config.cookieName);\n });\n\n logger.debug(`${req.url} | proxy FronteggCookies (${fronteggCookiesNames.join(', ')})`);\n fronteggCookiesNames.forEach((cookieName: string) => {\n proxyReq.setHeader(cookieName, allCookies[cookieName]);\n });\n\n proxyReq.setHeader('x-frontegg-framework', req.headers['x-frontegg-framework'] ?? `next@${NextJsPkg.version}`);\n proxyReq.setHeader('x-frontegg-sdk', req.headers['x-frontegg-sdk'] ?? `@frontegg/nextjs@${sdkVersion.version}`);\n proxyReq.setHeader('x-frontegg-middleware', 'true');\n\n HEADERS_TO_KEEP.forEach((header) => {\n const headerValue = req.headers[header];\n if (headerValue) {\n proxyReq.setHeader(header, headerValue);\n }\n });\n HEADERS_TO_REMOVE.map((header) => proxyReq.removeHeader(header));\n\n logger.debug(`${req.url} | check if request has body`);\n if (req.method !== 'GET' && req.body) {\n logger.debug(`${req.url} | writing request body to proxyReq`);\n const bodyData = JSON.stringify(req.body);\n // in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json\n proxyReq.setHeader('Content-Type', 'application/json');\n proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));\n // stream the content\n proxyReq.write(bodyData);\n }\n } catch (e) {\n logger.error(`${req.url} | Failed to proxy request`, e);\n }\n};\n\nexport default ProxyRequestCallback;\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,MAAMK,eAAe,GAAG,CAAC,iBAAiB,EAAE,0BAA0B,EAAE,kBAAkB,CAAC;AAC3F,MAAMC,iBAAiB,GAAG,CACxB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,CAChB;AACD,MAAMC,MAAM,GAAGC,uBAAc,CAACC,KAAK,CAAC;EAAEC,GAAG,EAAE;AAA6C,CAAC,CAAC;AAC1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,oBAAqE,GAAGA,CAACC,QAAQ,EAAEC,GAAG,KAAK;EAC/F,IAAI;IAAA,IAAAC,oBAAA,EAAAC,qBAAA;IACFR,MAAM,CAACS,IAAI,CAAE,GAAEH,GAAG,CAACI,GAAI,2BAA0B,CAAC;IAClDV,MAAM,CAACS,IAAI,CAAC,8BAA8B,EAAE;MAAEE,OAAO,EAAEL,GAAG,CAACK;IAAQ,CAAC,CAAC;IACrEX,MAAM,CAAC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RequestCallback.js","names":["_package","_interopRequireDefault","require","_sdkVersion","_config","_cookies","_fronteggLogger","HEADERS_TO_KEEP","HEADERS_TO_REMOVE","logger","fronteggLogger","child","tag","ProxyRequestCallback","proxyReq","req","_req$headers$xFronte","_req$headers$xFronte2","info","url","headers","debug","allCookies","CookieManager","parseCookieHeader","fronteggCookiesNames","Object","keys","filter","cookieName","startsWith","config","join","forEach","setHeader","NextJsPkg","version","sdkVersion","header","headerValue","console","log","map","removeHeader","method","body","bodyData","JSON","stringify","Buffer","byteLength","write","e","error","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyRequestCallback.ts"],"sourcesContent":["import NextJsPkg from 'next/package.json';\nimport { ProxyReqCallback } from 'http-proxy';\nimport { ClientRequest } from 'http';\nimport { NextApiRequest } from 'next';\nimport sdkVersion from '../sdkVersion';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport fronteggLogger from '../utils/fronteggLogger';\n\nconst HEADERS_TO_KEEP = ['x-forwarded-for', 'x-original-forwarded-for', 'cf-connecting-ip'];\nconst HEADERS_TO_REMOVE = [\n 'x-forwarded-port',\n 'x-invoke-path',\n 'x-invoke-query',\n 'x-middleware-invoke',\n 'x-middleware-next',\n 'transfer-encoding',\n 'cache-control',\n];\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyRequestCallback' });\n/**\n * Proxy request callback fired on before each request to Frontegg services,\n * to transport frontegg cookies.\n *\n * @param {ClientRequest} proxyReq - Proxy request to be sent\n * @param {NextApiRequest} req - Next.js incoming request\n */\nconst ProxyRequestCallback: ProxyReqCallback<ClientRequest, NextApiRequest> = (proxyReq, req) => {\n try {\n logger.info(`${req.url} | Going to proxy request`);\n logger.info('The original req headers are', { headers: req.headers });\n logger.debug(`${req.url} | parsing request cookies`);\n const allCookies = CookieManager.parseCookieHeader(req);\n logger.debug(`${req.url} | found ${allCookies} cookies`);\n const fronteggCookiesNames = Object.keys(allCookies).filter((cookieName) => {\n return cookieName.startsWith('fe_') && !cookieName.startsWith(config.cookieName);\n });\n\n logger.debug(`${req.url} | proxy FronteggCookies (${fronteggCookiesNames.join(', ')})`);\n fronteggCookiesNames.forEach((cookieName: string) => {\n proxyReq.setHeader(cookieName, allCookies[cookieName]);\n });\n\n proxyReq.setHeader('x-frontegg-framework', req.headers['x-frontegg-framework'] ?? `next@${NextJsPkg.version}`);\n proxyReq.setHeader('x-frontegg-sdk', req.headers['x-frontegg-sdk'] ?? `@frontegg/nextjs@${sdkVersion.version}`);\n proxyReq.setHeader('x-frontegg-middleware', 'true');\n\n HEADERS_TO_KEEP.forEach((header) => {\n const headerValue = req.headers[header];\n console.log(`headerValue for ${header} is `, headerValue);\n if (headerValue && headerValue != 'undefined') {\n proxyReq.setHeader(header, headerValue);\n }\n });\n HEADERS_TO_REMOVE.map((header) => proxyReq.removeHeader(header));\n\n logger.debug(`${req.url} | check if request has body`);\n if (req.method !== 'GET' && req.body) {\n logger.debug(`${req.url} | writing request body to proxyReq`);\n const bodyData = JSON.stringify(req.body);\n // in case if content-type is application/x-www-form-urlencoded -> we need to change to application/json\n proxyReq.setHeader('Content-Type', 'application/json');\n proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));\n // stream the content\n proxyReq.write(bodyData);\n }\n } catch (e) {\n logger.error(`${req.url} | Failed to proxy request`, e);\n }\n};\n\nexport default ProxyRequestCallback;\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,MAAMK,eAAe,GAAG,CAAC,iBAAiB,EAAE,0BAA0B,EAAE,kBAAkB,CAAC;AAC3F,MAAMC,iBAAiB,GAAG,CACxB,kBAAkB,EAClB,eAAe,EACf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;MACjE;MACAhC,QAAQ,CAACqC,KAAK,CAACL,QAAQ,CAAC;IAC1B;EACF,CAAC,CAAC,OAAOM,CAAC,EAAE;IACV3C,MAAM,CAAC4C,KAAK,CAAE,GAAEtC,GAAG,CAACI,GAAI,4BAA2B,EAAEiC,CAAC,CAAC;EACzD;AACF,CAAC;AAAC,IAAAE,QAAA,GAEazC,oBAAoB;AAAA0C,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -84,7 +84,11 @@ const ProxyResponseCallback = (proxyRes, req, res) => {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
Object.keys(proxyRes.headers).filter(header => header !== 'cookie').forEach(header => {
|
|
87
|
-
|
|
87
|
+
const headerValue = proxyRes.headers[header];
|
|
88
|
+
console.log(`headerValue for ${header} is `, headerValue);
|
|
89
|
+
if (headerValue && headerValue != 'undefined') {
|
|
90
|
+
res.setHeader(header, `${headerValue}`);
|
|
91
|
+
}
|
|
88
92
|
});
|
|
89
93
|
res.setHeader('set-cookie', cookies);
|
|
90
94
|
res.status(statusCode).end(bodyStr);
|
|
@@ -93,7 +97,11 @@ const ProxyResponseCallback = (proxyRes, req, res) => {
|
|
|
93
97
|
logger.error(`Middleware request failed statusCode: ${statusCode} for url: ${url}`);
|
|
94
98
|
}
|
|
95
99
|
Object.keys(proxyRes.headers).filter(header => header !== 'cookie').forEach(header => {
|
|
96
|
-
|
|
100
|
+
const headerValue = proxyRes.headers[header];
|
|
101
|
+
console.log(`headerValue for ${header} is `, headerValue);
|
|
102
|
+
if (headerValue && headerValue != 'undefined') {
|
|
103
|
+
res.setHeader(header, `${headerValue}`);
|
|
104
|
+
}
|
|
97
105
|
});
|
|
98
106
|
res.status(statusCode).end(bodyStr);
|
|
99
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyResponseCallback.js","names":["_config","_interopRequireDefault","require","_cookies","_common","_helpers","_fronteggLogger","_helpers2","logger","fronteggLogger","child","tag","ProxyResponseCallback","proxyRes","req","res","buffer","Buffer","totalLength","isSecured","URL","config","appUrl","protocol","on","chunk","length","concat","_proxyRes$statusCode","url","statusCode","isSuccess","bodyStr","toString","isLogout","isFronteggLogoutUrl","CookieManager","removeCookies","cookieDomain","status","end","_CookieManager$modify","cookies","modifySetCookie","headers","body","JSON","parse","accessToken","access_token","session","decodedJwt","createSessionFromAccessToken","sessionCookie","create","value","expires","Date","exp","secure","push","e","isSSOPostRequest","error","Object","keys","filter","header","forEach","setHeader","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyResponseCallback.ts"],"sourcesContent":["import { ProxyResCallback } from 'http-proxy';\nimport { IncomingMessage } from 'http';\nimport { NextApiResponse } from 'next';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport { createSessionFromAccessToken } from '../common';\nimport { isFronteggLogoutUrl } from './helpers';\nimport fronteggLogger from '../utils/fronteggLogger';\nimport { isSSOPostRequest } from '../utils/refreshAccessToken/helpers';\n\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyResponseCallback' });\n/**\n * Proxy response callback fired on after each response from Frontegg services,\n * to transport frontegg modify cookies and generating encrypted JWT session cookie.\n *\n * @param {IncomingMessage} proxyRes - Proxy response from Frontegg services\n * @param {NextApiRequest} req - Next.js request sent from client-side\n * @param {NextApiResponse} res - Next.js response to send to client-side\n */\nconst ProxyResponseCallback: ProxyResCallback<IncomingMessage, NextApiResponse> = (proxyRes, req, res) => {\n let buffer = new Buffer('');\n let totalLength: number = 0;\n const isSecured = new URL(config.appUrl).protocol === 'https:';\n\n proxyRes.on('data', (chunk: Buffer) => {\n totalLength += chunk.length;\n buffer = Buffer.concat([buffer, chunk], totalLength);\n });\n proxyRes.on('end', async () => {\n try {\n const url = req.url!;\n const statusCode = proxyRes.statusCode ?? 500;\n const isSuccess = statusCode >= 200 && statusCode < 400;\n const bodyStr = buffer.toString('utf-8');\n const isLogout = isFronteggLogoutUrl(url);\n\n if (isLogout) {\n CookieManager.removeCookies({\n isSecured,\n cookieDomain: config.cookieDomain,\n res,\n req,\n });\n res.status(statusCode).end(bodyStr);\n return;\n }\n\n if (isSuccess) {\n const cookies = CookieManager.modifySetCookie(proxyRes.headers['set-cookie'], isSecured) ?? [];\n\n try {\n if (bodyStr && bodyStr.length > 0) {\n const body = JSON.parse(bodyStr);\n if (body.accessToken || body.access_token) {\n const [session, decodedJwt] = await createSessionFromAccessToken(body);\n if (session) {\n const sessionCookie = CookieManager.create({\n value: session,\n expires: new Date(decodedJwt.exp * 1000),\n secure: isSecured,\n req,\n });\n cookies.push(...sessionCookie);\n }\n }\n }\n } catch (e) {\n /** ignore api call if:\n * - Does not have accessToken / access_token\n * - Not json response\n */\n if (statusCode === 302 && isSSOPostRequest(url)) {\n /**\n * Ignore saml/oidc postLogin response with redirect\n */\n } else {\n logger.error('failed to create session', e, {\n url,\n statusCode,\n });\n }\n }\n Object.keys(proxyRes.headers)\n .filter((header) => header !== 'cookie')\n .forEach((header) => {\n res.setHeader(header, `${
|
|
1
|
+
{"version":3,"file":"ProxyResponseCallback.js","names":["_config","_interopRequireDefault","require","_cookies","_common","_helpers","_fronteggLogger","_helpers2","logger","fronteggLogger","child","tag","ProxyResponseCallback","proxyRes","req","res","buffer","Buffer","totalLength","isSecured","URL","config","appUrl","protocol","on","chunk","length","concat","_proxyRes$statusCode","url","statusCode","isSuccess","bodyStr","toString","isLogout","isFronteggLogoutUrl","CookieManager","removeCookies","cookieDomain","status","end","_CookieManager$modify","cookies","modifySetCookie","headers","body","JSON","parse","accessToken","access_token","session","decodedJwt","createSessionFromAccessToken","sessionCookie","create","value","expires","Date","exp","secure","push","e","isSSOPostRequest","error","Object","keys","filter","header","forEach","headerValue","console","log","setHeader","_default","exports","default"],"sources":["../../../../packages/nextjs/src/middleware/ProxyResponseCallback.ts"],"sourcesContent":["import { ProxyResCallback } from 'http-proxy';\nimport { IncomingMessage } from 'http';\nimport { NextApiResponse } from 'next';\nimport config from '../config';\nimport CookieManager from '../utils/cookies';\nimport { createSessionFromAccessToken } from '../common';\nimport { isFronteggLogoutUrl } from './helpers';\nimport fronteggLogger from '../utils/fronteggLogger';\nimport { isSSOPostRequest } from '../utils/refreshAccessToken/helpers';\n\nconst logger = fronteggLogger.child({ tag: 'FronteggApiMiddleware.ProxyResponseCallback' });\n/**\n * Proxy response callback fired on after each response from Frontegg services,\n * to transport frontegg modify cookies and generating encrypted JWT session cookie.\n *\n * @param {IncomingMessage} proxyRes - Proxy response from Frontegg services\n * @param {NextApiRequest} req - Next.js request sent from client-side\n * @param {NextApiResponse} res - Next.js response to send to client-side\n */\nconst ProxyResponseCallback: ProxyResCallback<IncomingMessage, NextApiResponse> = (proxyRes, req, res) => {\n let buffer = new Buffer('');\n let totalLength: number = 0;\n const isSecured = new URL(config.appUrl).protocol === 'https:';\n\n proxyRes.on('data', (chunk: Buffer) => {\n totalLength += chunk.length;\n buffer = Buffer.concat([buffer, chunk], totalLength);\n });\n proxyRes.on('end', async () => {\n try {\n const url = req.url!;\n const statusCode = proxyRes.statusCode ?? 500;\n const isSuccess = statusCode >= 200 && statusCode < 400;\n const bodyStr = buffer.toString('utf-8');\n const isLogout = isFronteggLogoutUrl(url);\n\n if (isLogout) {\n CookieManager.removeCookies({\n isSecured,\n cookieDomain: config.cookieDomain,\n res,\n req,\n });\n res.status(statusCode).end(bodyStr);\n return;\n }\n\n if (isSuccess) {\n const cookies = CookieManager.modifySetCookie(proxyRes.headers['set-cookie'], isSecured) ?? [];\n\n try {\n if (bodyStr && bodyStr.length > 0) {\n const body = JSON.parse(bodyStr);\n if (body.accessToken || body.access_token) {\n const [session, decodedJwt] = await createSessionFromAccessToken(body);\n if (session) {\n const sessionCookie = CookieManager.create({\n value: session,\n expires: new Date(decodedJwt.exp * 1000),\n secure: isSecured,\n req,\n });\n cookies.push(...sessionCookie);\n }\n }\n }\n } catch (e) {\n /** ignore api call if:\n * - Does not have accessToken / access_token\n * - Not json response\n */\n if (statusCode === 302 && isSSOPostRequest(url)) {\n /**\n * Ignore saml/oidc postLogin response with redirect\n */\n } else {\n logger.error('failed to create session', e, {\n url,\n statusCode,\n });\n }\n }\n Object.keys(proxyRes.headers)\n .filter((header) => header !== 'cookie')\n .forEach((header) => {\n const headerValue = proxyRes.headers[header];\n console.log(`headerValue for ${header} is `, headerValue);\n if (headerValue && headerValue != 'undefined') {\n res.setHeader(header, `${headerValue}`);\n }\n });\n res.setHeader('set-cookie', cookies);\n res.status(statusCode).end(bodyStr);\n } else {\n if (statusCode >= 400 && statusCode !== 404) {\n logger.error(`Middleware request failed statusCode: ${statusCode} for url: ${url}`);\n }\n Object.keys(proxyRes.headers)\n .filter((header) => header !== 'cookie')\n .forEach((header) => {\n const headerValue = proxyRes.headers[header];\n console.log(`headerValue for ${header} is `, headerValue);\n if (headerValue && headerValue != 'undefined') {\n res.setHeader(header, `${headerValue}`);\n }\n });\n res.status(statusCode).end(bodyStr);\n }\n } catch (e: any) {\n logger.error('proxy failed to send request', e);\n res.status(500).end('Internal Server Error');\n }\n });\n};\n\nexport default ProxyResponseCallback;\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAEA,MAAMM,MAAM,GAAGC,uBAAc,CAACC,KAAK,CAAC;EAAEC,GAAG,EAAE;AAA8C,CAAC,CAAC;AAC3F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,qBAAyE,GAAGA,CAACC,QAAQ,EAAEC,GAAG,EAAEC,GAAG,KAAK;EACxG,IAAIC,MAAM,GAAG,IAAIC,MAAM,CAAC,EAAE,CAAC;EAC3B,IAAIC,WAAmB,GAAG,CAAC;EAC3B,MAAMC,SAAS,GAAG,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SAAS,CAAC,YAAY,EAAE9B,OAAO,CAAC;QACpC3B,GAAG,CAACwB,MAAM,CAACT,UAAU,CAAC,CAACU,GAAG,CAACR,OAAO,CAAC;MACrC,CAAC,MAAM;QACL,IAAIF,UAAU,IAAI,GAAG,IAAIA,UAAU,KAAK,GAAG,EAAE;UAC3CtB,MAAM,CAACuD,KAAK,CAAE,yCAAwCjC,UAAW,aAAYD,GAAI,EAAC,CAAC;QACrF;QACAmC,MAAM,CAACC,IAAI,CAACpD,QAAQ,CAAC+B,OAAO,CAAC,CAC1BsB,MAAM,CAAEC,MAAM,IAAKA,MAAM,KAAK,QAAQ,CAAC,CACvCC,OAAO,CAAED,MAAM,IAAK;UACnB,MAAME,WAAW,GAAGxD,QAAQ,CAAC+B,OAAO,CAACuB,MAAM,CAAC;UAC5CG,OAAO,CAACC,GAAG,CAAE,mBAAkBJ,MAAO,MAAK,EAAEE,WAAW,CAAC;UACzD,IAAIA,WAAW,IAAIA,WAAW,IAAI,WAAW,EAAE;YAC7CtD,GAAG,CAACyD,SAAS,CAACL,MAAM,EAAG,GAAEE,WAAY,EAAC,CAAC;UACzC;QACF,CAAC,CAAC;QACJtD,GAAG,CAACwB,MAAM,CAACT,UAAU,CAAC,CAACU,GAAG,CAACR,OAAO,CAAC;MACrC;IACF,CAAC,CAAC,OAAO6B,CAAM,EAAE;MACfrD,MAAM,CAACuD,KAAK,CAAC,8BAA8B,EAAEF,CAAC,CAAC;MAC/C9C,GAAG,CAACwB,MAAM,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,uBAAuB,CAAC;IAC9C;EACF,CAAC,CAAC;AACJ,CAAC;AAAC,IAAAiC,QAAA,GAEa7D,qBAAqB;AAAA8D,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/package.json
CHANGED
package/sdkVersion.js
CHANGED
package/sdkVersion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkVersion.js","names":["version","exports","default","_default"],"sources":["../../../packages/nextjs/src/sdkVersion.ts"],"sourcesContent":["export default { version: '8.0.11-alpha.
|
|
1
|
+
{"version":3,"file":"sdkVersion.js","names":["version","exports","default","_default"],"sources":["../../../packages/nextjs/src/sdkVersion.ts"],"sourcesContent":["export default { version: '8.0.11-alpha.7460792997' };\n"],"mappings":";;;;;;eAAe;EAAEA,OAAO,EAAE;AAA0B,CAAC;AAAAC,OAAA,CAAAC,OAAA,GAAAC,QAAA"}
|