MCPcopy Index your code
hub / github.com/ModelEngine-Group/nexent / prepareAuthRequestBody

Function prepareAuthRequestBody

frontend/server.js:184–204  ·  view source on GitHub ↗

* For the refresh_token endpoint, inject the refresh_token from cookie * into the request body so the backend can process it normally. * If no refresh_token cookie exists, return 401 immediately.

(pathname, body, cookies, res)

Source from the content-addressed store, hash-verified

182 * If no refresh_token cookie exists, return 401 immediately.
183 */
184function prepareAuthRequestBody(pathname, body, cookies, res) {
185 if (
186 pathname === "/api/user/refresh_token" ) {
187 const refreshToken =
188 cookies[COOKIE_NAMES.REFRESH_TOKEN]
189 ;
190 if (!refreshToken) {
191 res.writeHead(401, { "Content-Type": "application/json" });
192 res.end(JSON.stringify({ detail: "No refresh token cookie found" }));
193 return null;
194 }
195 try {
196 const parsed = body.length > 0 ? JSON.parse(body.toString()) : {};
197 parsed.refresh_token = refreshToken;
198 return Buffer.from(JSON.stringify(parsed));
199 } catch {
200 return body;
201 }
202 }
203 return body;
204}
205
206function forwardAuthRequest(req, res, targetUrl) {
207 const parsedTarget = new URL(targetUrl);

Callers 1

forwardAuthRequestFunction · 0.85

Calls 2

toStringMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected