Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@authx/http-proxy-client

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@authx/http-proxy-client - npm Package Compare versions

Comparing version 3.1.0-alpha.20 to 3.1.0-alpha.21

14

dist/index.d.ts

@@ -5,3 +5,3 @@ /// <reference types="node" />

import { ServerOptions } from "http-proxy";
interface Behavior {
export interface Behavior {
/**

@@ -47,4 +47,11 @@ * The options to pass to node-proxy.

readonly sendTokenToTargetWithScopes?: string[];
/**
* Format (BEARER or BASIC) of tokens that the proxy will request from AuthX and pass to the
* the resource.
*
* If unspecified, the format BEARER will be used.
*/
readonly tokenFormat?: "BASIC" | "BEARER";
}
interface Rule {
export interface Rule {
/**

@@ -69,3 +76,3 @@ * Each rule is tested in order, with the first to return `true` used to

}
interface Config {
export interface Config {
/**

@@ -212,2 +219,1 @@ * The root URL to AuthX server.

}
export {};

@@ -61,3 +61,3 @@ "use strict";

behavior: undefined,
message: "Request received."
message: "Request received.",
};

@@ -133,3 +133,3 @@ // Emit meta on request start.

meta.behavior = behavior;
this._proxy.web(request, response, behavior.proxyOptions, error => {
this._proxy.web(request, response, behavior.proxyOptions, (error) => {
if (!response.headersSent) {

@@ -268,4 +268,2 @@ const code = error.code;

try {
// FIXME: This should not need to be cast through any. See:
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/35636
const refreshResponse = await node_fetch_1.default(this._config.authxUrl, {

@@ -275,3 +273,3 @@ method: "POST",

headers: {
"Content-Type": "application/json"
"Content-Type": "application/json",
},

@@ -285,5 +283,4 @@ body: JSON.stringify({

refresh_token: refreshToken,
scope: scopes.join(" ")
/* eslint-enable camelcase */
})
scope: scopes.join(" "),
}),
});

@@ -308,3 +305,3 @@ if (refreshResponse.status !== 200) {

// BASIC tokens never expire, so this is not applicable to them.
if (((_a = refreshResponseBody.token_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == "bearer") {
if (((_a = refreshResponseBody.token_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "bearer") {
const payload = jsonwebtoken_1.decode(accessToken);

@@ -387,3 +384,3 @@ if (!payload || typeof payload !== "object") {

}
})()
})(),
};

@@ -402,3 +399,3 @@ // Store the request.

}
return new Promise(resolve => {
return new Promise((resolve) => {
this.server.once("listening", resolve);

@@ -444,3 +441,3 @@ this.server.listen(options);

// Close the proxy.
return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(() => {

@@ -447,0 +444,0 @@ this.server.close(() => {

@@ -43,3 +43,3 @@ "use strict";

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: body.client_id
aud: body.client_id,
}))

@@ -50,4 +50,3 @@ .toString("base64")

expires_in: 3600,
scope: body.scope
/* eslint-enable camelcase */
scope: body.scope,
}));

@@ -83,3 +82,3 @@ });

url: request.url,
token: JSON.parse(decoded)
token: JSON.parse(decoded),
}));

@@ -96,3 +95,3 @@ });

server.listen(undefined, "localhost");
})
}),
]);

@@ -112,4 +111,4 @@ mockAuthX = mocks[0];

behavior: {
proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` }
}
proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` },
},
},

@@ -122,4 +121,4 @@ {

proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` },
refreshToken: "cbfd6ad6-b770-4ffd-911d-d999a894a0fb"
}
refreshToken: "cbfd6ad6-b770-4ffd-911d-d999a894a0fb",
},
},

@@ -133,4 +132,4 @@ {

refreshToken: "cbfd6ad6-b770-4ffd-911d-d999a894a0fb",
sendTokenToTargetWithScopes: ["foo:**:**"]
}
sendTokenToTargetWithScopes: ["foo:**:**"],
},
},

@@ -146,9 +145,9 @@ {

refreshToken: "58582764-308e-4eaa-9e72-dbb7e7f1c085",
sendTokenToTargetWithScopes: ["**:**:**"]
sendTokenToTargetWithScopes: ["**:**:**"],
};
}
}
]
},
},
],
});
proxy.on("error", error => console.error(error));
proxy.on("error", (error) => console.error(error));
await proxy.listen({ port: 0, host: "localhost" });

@@ -171,3 +170,3 @@ const address = proxy && proxy.server.address();

url: "/no-token",
token: null
token: null,
});

@@ -186,4 +185,4 @@ });

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0"
}
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0",
},
});

@@ -202,4 +201,4 @@ });

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0"
}
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0",
},
});

@@ -218,6 +217,6 @@ });

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0"
}
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0",
},
});
});
//# sourceMappingURL=index.test.js.map

@@ -18,4 +18,4 @@ {

"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.9.1",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"ava": "^3.5.2",

@@ -57,3 +57,3 @@ "eslint": "^7.7.0",

"types": "./dist/index.d.ts",
"version": "3.1.0-alpha.20"
"version": "3.1.0-alpha.21"
}

@@ -26,4 +26,4 @@ # HTTP Proxy - Client

behavior: {
proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` }
}
proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` },
},
},

@@ -40,4 +40,4 @@

refreshToken: process.env.REFRESH_TOKEN,
sendTokenToTargetWithScopes: ["foo:**:**"]
}
sendTokenToTargetWithScopes: ["foo:**:**"],
},
},

@@ -58,7 +58,7 @@

refreshToken,
sendTokenToTargetWithScopes: ["**:**:**"]
sendTokenToTargetWithScopes: ["**:**:**"],
};
}
}
]
},
},
],
});

@@ -65,0 +65,0 @@ ```

@@ -57,3 +57,3 @@ import test from "ava";

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: body.client_id
aud: body.client_id,
})

@@ -68,3 +68,3 @@ )

expires_in: 3600,
scope: body.scope
scope: body.scope,
/* eslint-enable camelcase */

@@ -114,3 +114,3 @@ })

url: request.url,
token: JSON.parse(decoded)
token: JSON.parse(decoded),
})

@@ -131,3 +131,3 @@ );

server.listen(undefined, "localhost");
})
}),
]);

@@ -149,4 +149,4 @@

behavior: {
proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` }
}
proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` },
},
},

@@ -159,4 +159,4 @@ {

proxyOptions: { target: `http://127.0.0.1:${mockTarget.port}` },
refreshToken: "cbfd6ad6-b770-4ffd-911d-d999a894a0fb"
}
refreshToken: "cbfd6ad6-b770-4ffd-911d-d999a894a0fb",
},
},

@@ -170,4 +170,4 @@ {

refreshToken: "cbfd6ad6-b770-4ffd-911d-d999a894a0fb",
sendTokenToTargetWithScopes: ["foo:**:**"]
}
sendTokenToTargetWithScopes: ["foo:**:**"],
},
},

@@ -183,10 +183,10 @@ {

refreshToken: "58582764-308e-4eaa-9e72-dbb7e7f1c085",
sendTokenToTargetWithScopes: ["**:**:**"]
sendTokenToTargetWithScopes: ["**:**:**"],
};
}
}
]
},
},
],
});
proxy.on("error", error => console.error(error));
proxy.on("error", (error) => console.error(error));

@@ -202,3 +202,3 @@ await proxy.listen({ port: 0, host: "localhost" });

test("readiness endpoint", async t => {
test("readiness endpoint", async (t) => {
const response = await fetch(`http://127.0.0.1:${port}/_ready`);

@@ -209,3 +209,3 @@ t.is(response.status, 200);

test("no token", async t => {
test("no token", async (t) => {
const result = await fetch(`http://127.0.0.1:${port}/no-token`);

@@ -215,7 +215,7 @@ t.assert(result.status === 200);

url: "/no-token",
token: null
token: null,
});
});
test("with static token", async t => {
test("with static token", async (t) => {
const result = await fetch(`http://127.0.0.1:${port}/with-static-token`);

@@ -231,8 +231,8 @@ t.assert(result.status === 200);

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0"
}
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0",
},
});
});
test("with static token and scopes", async t => {
test("with static token and scopes", async (t) => {
const result = await fetch(

@@ -250,8 +250,8 @@ `http://127.0.0.1:${port}/with-static-token-and-scopes`

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0"
}
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0",
},
});
});
test("with dynamic token and scopes", async t => {
test("with dynamic token and scopes", async (t) => {
const result = await fetch(

@@ -269,5 +269,5 @@ `http://127.0.0.1:${port}/with-dynamic-token-and-scopes`

sub: "c79a01a2-0ed7-45c5-93b8-bc921d5cf368",
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0"
}
aud: "b22282bf-1b78-4ffc-a0d6-2da5465895d0",
},
});
});

@@ -9,3 +9,3 @@ import { createHash } from "crypto";

interface Behavior {
export interface Behavior {
/**

@@ -53,5 +53,13 @@ * The options to pass to node-proxy.

readonly sendTokenToTargetWithScopes?: string[];
/**
* Format (BEARER or BASIC) of tokens that the proxy will request from AuthX and pass to the
* the resource.
*
* If unspecified, the format BEARER will be used.
*/
readonly tokenFormat?: "BASIC" | "BEARER";
}
interface Rule {
export interface Rule {
/**

@@ -83,3 +91,3 @@ * Each rule is tested in order, with the first to return `true` used to

interface Config {
export interface Config {
/**

@@ -269,3 +277,3 @@ * The root URL to AuthX server.

behavior: undefined,
message: "Request received."
message: "Request received.",
};

@@ -356,3 +364,3 @@

meta.behavior = behavior;
this._proxy.web(request, response, behavior.proxyOptions, error => {
this._proxy.web(request, response, behavior.proxyOptions, (error) => {
if (!response.headersSent) {

@@ -518,4 +526,2 @@ const code = (error as any).code;

try {
// FIXME: This should not need to be cast through any. See:
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/35636
const refreshResponse = await fetch(this._config.authxUrl, {

@@ -525,3 +531,3 @@ method: "POST",

headers: {
"Content-Type": "application/json"
"Content-Type": "application/json",
},

@@ -535,6 +541,6 @@ body: JSON.stringify({

refresh_token: refreshToken,
scope: scopes.join(" ")
scope: scopes.join(" "),
/* eslint-enable camelcase */
})
} as any);
}),
});

@@ -567,3 +573,3 @@ if (refreshResponse.status !== 200) {

// BASIC tokens never expire, so this is not applicable to them.
if (refreshResponseBody.token_type?.toLowerCase() == "bearer") {
if (refreshResponseBody.token_type?.toLowerCase() === "bearer") {
const payload = decode(accessToken);

@@ -666,3 +672,3 @@ if (!payload || typeof payload !== "object") {

}
})()
})(),
};

@@ -698,3 +704,3 @@

return new Promise(resolve => {
return new Promise((resolve) => {
this.server.once("listening", resolve);

@@ -748,3 +754,3 @@ this.server.listen(options);

// Close the proxy.
return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(() => {

@@ -751,0 +757,0 @@ this.server.close(() => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc