@dropsh/plugin-oauth2 0.7.0 → 0.7.2
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.
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
import { ConfigError } from "dropsh/plugin";
|
|
2
2
|
import { oauth2Provider } from "./provider.js";
|
|
3
|
+
/**
|
|
4
|
+
* `token_url` is composed by the consumer's config as `${base_url}/oauth/token`,
|
|
5
|
+
* so a trailing slash on `base_url` yields `https://host//oauth/token`. That URL
|
|
6
|
+
* never reaches the token endpoint — a proxy collapses or redirects the empty
|
|
7
|
+
* segment — and the server's reply names no cause. Reject the shape before any
|
|
8
|
+
* request is issued, since `token_url` arrives pre-composed and never passes
|
|
9
|
+
* through `loadConfig` (DROPSH-13).
|
|
10
|
+
*
|
|
11
|
+
* The check reads the *path*, never the whole string: the `//` in `https://` is
|
|
12
|
+
* the scheme separator and must not be mistaken for the defect. A `token_url`
|
|
13
|
+
* that does not parse as an absolute URL is left to the request layer.
|
|
14
|
+
*/
|
|
15
|
+
function assertCanonicalTokenUrl(tokenUrl) {
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = new URL(tokenUrl);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!parsed.pathname.includes("//"))
|
|
24
|
+
return;
|
|
25
|
+
parsed.pathname = parsed.pathname.replace(/\/{2,}/g, "/");
|
|
26
|
+
throw new ConfigError(`oauth2Plugin: token_url must not contain an empty path segment — set it to ${parsed.href}`);
|
|
27
|
+
}
|
|
3
28
|
function validate(config) {
|
|
4
29
|
if (!config.client_id)
|
|
5
30
|
throw new ConfigError("oauth2Plugin: client_id required");
|
|
6
31
|
if (!config.token_url)
|
|
7
32
|
throw new ConfigError("oauth2Plugin: token_url required");
|
|
33
|
+
assertCanonicalTokenUrl(config.token_url);
|
|
8
34
|
if (config.type === "oauth2_password" && !config.username)
|
|
9
35
|
throw new ConfigError("oauth2Plugin: username required for oauth2_password");
|
|
10
36
|
return config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dropsh/plugin-oauth2",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/plugins/oauth2/src/index.js",
|
|
6
6
|
"types": "./dist/plugins/oauth2/src/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "^5.6.0",
|
|
25
25
|
"vitest": "^4.1.8",
|
|
26
|
-
"dropsh": "0.7.
|
|
26
|
+
"dropsh": "0.7.2"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsc",
|