@scalar/api-client 2.31.2 → 2.32.0
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 +114 -0
- package/dist/style.css +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-example-from-schema.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-example-from-schema.js +73 -74
- package/dist/v2/blocks/request-block/helpers/get-default-headers.js +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.js +42 -40
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts +3 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js +65 -59
- package/dist/v2/features/operation/Operation.vue.js +1 -1
- package/dist/views/Request/ResponseSection/ResponseEmpty.vue2.js +1 -1
- package/dist/views/Request/libs/oauth2.d.ts +7 -0
- package/dist/views/Request/libs/oauth2.d.ts.map +1 -1
- package/dist/views/Request/libs/oauth2.js +76 -64
- package/package.json +25 -25
|
@@ -1,44 +1,49 @@
|
|
|
1
|
-
import { isRelativePath as
|
|
2
|
-
import { makeUrlAbsolute as
|
|
3
|
-
import { shouldUseProxy as
|
|
4
|
-
import { encode as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { isRelativePath as z } from "@scalar/helpers/url/is-relative-path";
|
|
2
|
+
import { makeUrlAbsolute as S } from "@scalar/helpers/url/make-url-absolute";
|
|
3
|
+
import { shouldUseProxy as F } from "@scalar/helpers/url/redirect-to-proxy";
|
|
4
|
+
import { encode as R, fromUint8Array as A } from "js-base64";
|
|
5
|
+
import { getServerUrl as E } from "../../operation-block/helpers/get-server-url.js";
|
|
6
|
+
const b = (t, e = {}) => {
|
|
7
|
+
const i = E(t, e);
|
|
8
|
+
return i ? z(i) ? typeof window > "u" ? {} : { basePath: i } : { baseUrl: i } : {};
|
|
9
|
+
}, $ = () => {
|
|
9
10
|
const t = new Uint8Array(32);
|
|
10
|
-
return crypto.getRandomValues(t),
|
|
11
|
-
},
|
|
11
|
+
return crypto.getRandomValues(t), A(t, !0);
|
|
12
|
+
}, L = async (t, e) => {
|
|
12
13
|
if (e === "plain")
|
|
13
14
|
return t;
|
|
14
15
|
if (typeof crypto?.subtle?.digest != "function")
|
|
15
16
|
return console.warn("SHA-256 is only supported when using https, using a plain text code challenge instead."), t;
|
|
16
|
-
const
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
const
|
|
17
|
+
const d = new TextEncoder().encode(t), m = await crypto.subtle.digest("SHA-256", d);
|
|
18
|
+
return A(new Uint8Array(m), !0);
|
|
19
|
+
}, q = async (t, e, i, d, m, g = {}) => {
|
|
20
|
+
const h = t[e];
|
|
20
21
|
try {
|
|
21
|
-
if (!
|
|
22
|
+
if (!h)
|
|
22
23
|
return [new Error("Flow not found"), null];
|
|
23
|
-
const
|
|
24
|
+
const p = i.join(" ");
|
|
24
25
|
if (e === "clientCredentials" || e === "password")
|
|
25
|
-
return
|
|
26
|
+
return C(
|
|
26
27
|
t,
|
|
27
28
|
e,
|
|
28
|
-
|
|
29
|
+
p,
|
|
29
30
|
{
|
|
30
|
-
proxyUrl:
|
|
31
|
+
proxyUrl: m
|
|
31
32
|
},
|
|
32
|
-
|
|
33
|
+
d,
|
|
34
|
+
g
|
|
33
35
|
);
|
|
34
|
-
const r = (Math.random() + 1).toString(36).substring(2, 10), a =
|
|
36
|
+
const r = (Math.random() + 1).toString(36).substring(2, 10), a = S(
|
|
37
|
+
t[e].authorizationUrl,
|
|
38
|
+
b(d, g)
|
|
39
|
+
), n = new URL(a);
|
|
35
40
|
let c = null;
|
|
36
41
|
if (e === "implicit")
|
|
37
42
|
n.searchParams.set("response_type", "token");
|
|
38
43
|
else if (e === "authorizationCode") {
|
|
39
44
|
const s = t[e];
|
|
40
45
|
if (n.searchParams.set("response_type", "code"), s["x-usePkce"] !== "no") {
|
|
41
|
-
const o =
|
|
46
|
+
const o = $(), u = await L(o, s["x-usePkce"]);
|
|
42
47
|
c = {
|
|
43
48
|
codeVerifier: o,
|
|
44
49
|
codeChallenge: u,
|
|
@@ -46,76 +51,77 @@ const A = (t) => {
|
|
|
46
51
|
}, n.searchParams.set("code_challenge", u), n.searchParams.set("code_challenge_method", c.codeChallengeMethod);
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
const s =
|
|
54
|
+
const l = t[e];
|
|
55
|
+
if (l["x-scalar-secret-redirect-uri"].startsWith("/")) {
|
|
56
|
+
const s = E(d, g) || window.location.origin + window.location.pathname, o = new URL(l["x-scalar-secret-redirect-uri"], s).toString();
|
|
52
57
|
n.searchParams.set("redirect_uri", o);
|
|
53
58
|
} else
|
|
54
|
-
n.searchParams.set("redirect_uri",
|
|
55
|
-
|
|
56
|
-
const o =
|
|
59
|
+
n.searchParams.set("redirect_uri", l["x-scalar-secret-redirect-uri"]);
|
|
60
|
+
h["x-scalar-security-query"] && Object.keys(h["x-scalar-security-query"]).forEach((s) => {
|
|
61
|
+
const o = h["x-scalar-security-query"]?.[s];
|
|
57
62
|
o && n.searchParams.set(s, o);
|
|
58
|
-
}), n.searchParams.set("client_id",
|
|
59
|
-
const
|
|
60
|
-
return
|
|
63
|
+
}), n.searchParams.set("client_id", h["x-scalar-secret-client-id"]), n.searchParams.set("state", r), p && n.searchParams.set("scope", p);
|
|
64
|
+
const w = window.open(n, "openAuth2Window", "left=100,top=100,width=800,height=600");
|
|
65
|
+
return w ? new Promise((s) => {
|
|
61
66
|
const o = setInterval(() => {
|
|
62
|
-
let u = null,
|
|
67
|
+
let u = null, x = null, _ = null, P = null;
|
|
63
68
|
try {
|
|
64
|
-
const
|
|
65
|
-
u =
|
|
66
|
-
const
|
|
67
|
-
u ||=
|
|
69
|
+
const f = new URL(w.location.href).searchParams, U = h["x-tokenName"] || "access_token";
|
|
70
|
+
u = f.get(U), x = f.get("code"), _ = f.get("error"), P = f.get("error_description");
|
|
71
|
+
const y = new URLSearchParams(w.location.href.split("#")[1]);
|
|
72
|
+
u ||= y.get(U), x ||= y.get("code"), _ ||= y.get("error"), P ||= y.get("error_description");
|
|
68
73
|
} catch {
|
|
69
74
|
}
|
|
70
|
-
if (
|
|
71
|
-
if (clearInterval(o),
|
|
72
|
-
s([new Error(`OAuth error: ${
|
|
75
|
+
if (w.closed || u || x || _)
|
|
76
|
+
if (clearInterval(o), w.close(), _)
|
|
77
|
+
s([new Error(`OAuth error: ${_}${P ? ` (${P})` : ""}`), null]);
|
|
73
78
|
else if (u) {
|
|
74
|
-
const
|
|
75
|
-
s(
|
|
76
|
-
} else
|
|
79
|
+
const f = w.location.href.match(/state=([^&]*)/)?.[1];
|
|
80
|
+
s(f === r ? [null, u] : [new Error("State mismatch"), null]);
|
|
81
|
+
} else x && e === "authorizationCode" ? new URL(w.location.href).searchParams.get("state") === r ? C(
|
|
77
82
|
t,
|
|
78
83
|
e,
|
|
79
|
-
|
|
84
|
+
p,
|
|
80
85
|
{
|
|
81
|
-
code:
|
|
86
|
+
code: x,
|
|
82
87
|
pkce: c,
|
|
83
|
-
proxyUrl:
|
|
88
|
+
proxyUrl: m
|
|
84
89
|
},
|
|
85
|
-
|
|
90
|
+
d,
|
|
91
|
+
g
|
|
86
92
|
).then(s) : s([new Error("State mismatch"), null]) : (clearInterval(o), s([new Error("Window was closed without granting authorization"), null]));
|
|
87
93
|
}, 200);
|
|
88
94
|
}) : [new Error("Failed to open auth window"), null];
|
|
89
95
|
} catch {
|
|
90
96
|
return [new Error("Failed to authorize oauth2 flow"), null];
|
|
91
97
|
}
|
|
92
|
-
},
|
|
93
|
-
code:
|
|
94
|
-
pkce:
|
|
95
|
-
proxyUrl:
|
|
96
|
-
} = {},
|
|
98
|
+
}, C = async (t, e, i, {
|
|
99
|
+
code: d,
|
|
100
|
+
pkce: m,
|
|
101
|
+
proxyUrl: g
|
|
102
|
+
} = {}, h, p = {}) => {
|
|
97
103
|
const r = t[e];
|
|
98
104
|
if (!r)
|
|
99
105
|
return [new Error("OAuth2 flow was not defined"), null];
|
|
100
106
|
const a = new URLSearchParams();
|
|
101
|
-
|
|
107
|
+
i && (e === "clientCredentials" || e === "password") && a.set("scope", i);
|
|
102
108
|
const n = r["x-scalar-credentials-location"] === "body";
|
|
103
|
-
if (n && (a.set("client_id", r["x-scalar-secret-client-id"]), a.set("client_secret", r["x-scalar-secret-client-secret"])), "x-scalar-secret-redirect-uri" in r && r["x-scalar-secret-redirect-uri"] && a.set("redirect_uri", r["x-scalar-secret-redirect-uri"]),
|
|
104
|
-
a.set("code",
|
|
109
|
+
if (n && (a.set("client_id", r["x-scalar-secret-client-id"]), a.set("client_secret", r["x-scalar-secret-client-secret"])), "x-scalar-secret-redirect-uri" in r && r["x-scalar-secret-redirect-uri"] && a.set("redirect_uri", r["x-scalar-secret-redirect-uri"]), d)
|
|
110
|
+
a.set("code", d), a.set("grant_type", "authorization_code"), m && a.set("code_verifier", m.codeVerifier);
|
|
105
111
|
else if (e === "password") {
|
|
106
112
|
const c = t[e];
|
|
107
113
|
a.set("grant_type", "password"), a.set("username", c["x-scalar-secret-username"]), a.set("password", c["x-scalar-secret-password"]);
|
|
108
114
|
} else
|
|
109
115
|
a.set("grant_type", "client_credentials");
|
|
110
|
-
r["x-scalar-security-body"] && Object.entries(r["x-scalar-security-body"]).forEach(([c,
|
|
111
|
-
|
|
116
|
+
r["x-scalar-security-body"] && Object.entries(r["x-scalar-security-body"]).forEach(([c, l]) => {
|
|
117
|
+
l && a.set(c, l);
|
|
112
118
|
});
|
|
113
119
|
try {
|
|
114
120
|
const c = {
|
|
115
121
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
116
122
|
};
|
|
117
|
-
n || (c.Authorization = `Basic ${
|
|
118
|
-
const
|
|
123
|
+
n || (c.Authorization = `Basic ${R(`${r["x-scalar-secret-client-id"]}:${r["x-scalar-secret-client-secret"]}`)}`);
|
|
124
|
+
const l = S(r.tokenUrl, b(h, p)), k = F(g, l) ? `${g}?${new URLSearchParams([["scalar_url", l]]).toString()}` : l, s = await (await fetch(k, {
|
|
119
125
|
method: "POST",
|
|
120
126
|
headers: c,
|
|
121
127
|
body: a
|
|
@@ -126,5 +132,5 @@ const A = (t) => {
|
|
|
126
132
|
}
|
|
127
133
|
};
|
|
128
134
|
export {
|
|
129
|
-
|
|
135
|
+
q as authorizeOauth2
|
|
130
136
|
};
|
|
@@ -81,7 +81,7 @@ const P = {
|
|
|
81
81
|
)
|
|
82
82
|
)), x = t(
|
|
83
83
|
() => b(a(e.options)?.hiddenClients)
|
|
84
|
-
), g = "2.
|
|
84
|
+
), g = "2.32.0";
|
|
85
85
|
return (n, o) => e.path && e.method && e.exampleName && r.value ? (m(), C(c(V), {
|
|
86
86
|
key: 0,
|
|
87
87
|
activeEnvironment: e.workspaceStore.workspace["x-scalar-active-environment"],
|
|
@@ -33,7 +33,7 @@ const W = { class: "flex-center relative flex flex-1 flex-col gap-6 p-2 capitali
|
|
|
33
33
|
}));
|
|
34
34
|
}, f = (u) => {
|
|
35
35
|
u?.createNew && g.name === "request" && p();
|
|
36
|
-
}, v = "2.
|
|
36
|
+
}, v = "2.32.0";
|
|
37
37
|
return q(() => a.hotKeys.on(f)), R(() => a.hotKeys.off(f)), (u, e) => (l(), n("div", W, [
|
|
38
38
|
s("div", {
|
|
39
39
|
class: y(["flex h-[calc(100%_-_50px)] flex-col items-center justify-center", {
|
|
@@ -9,6 +9,13 @@ type PKCEState = {
|
|
|
9
9
|
codeChallenge: string;
|
|
10
10
|
codeChallengeMethod: string;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Interpolates server URL template variables (e.g. `https://{env}.example.com`)
|
|
14
|
+
* using the user-set `value` when available, falling back to the OpenAPI `default`.
|
|
15
|
+
* This is needed so OAuth flows that use the server URL as a base resolve correctly
|
|
16
|
+
* when the spec defines server variables.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getInterpolatedServerUrl: (activeServer?: Server) => string | undefined;
|
|
12
19
|
/**
|
|
13
20
|
* Creates a code challenge from the code verifier
|
|
14
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth2.d.ts","sourceRoot":"","sources":["../../../../src/views/Request/libs/oauth2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"oauth2.d.ts","sourceRoot":"","sources":["../../../../src/views/Request/libs/oauth2.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,qDAAqD;AACrD,KAAK,eAAe,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAA;AAEhE,KAAK,SAAS,GAAG;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,mBAAmB,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,eAAe,MAAM,KAAG,MAAM,GAAG,SAczE,CAAA;AA8BD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAU,UAAU,MAAM,EAAE,UAAU,SAAS,GAAG,OAAO,KAAG,OAAO,CAAC,MAAM,CAkB3G,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,UAAU;AAChB,wEAAwE;AACxE,cAAc,MAAM;AACpB,kCAAkC;AAClC,WAAW,MAAM,KAChB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CA0K/B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,eAAe,EACrB,QAAQ,MAAM,EACd,2BAIG;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,YAAK,EACN,cAAc,MAAM,GAAG,SAAS,KAC/B,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CA2F/B,CAAA"}
|
|
@@ -1,115 +1,127 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { replaceVariables as U } from "@scalar/helpers/regex/replace-variables";
|
|
2
|
+
import { isRelativePath as b } from "@scalar/helpers/url/is-relative-path";
|
|
2
3
|
import { makeUrlAbsolute as x } from "@scalar/helpers/url/make-url-absolute";
|
|
3
|
-
import { shouldUseProxy as
|
|
4
|
-
import { encode as
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { shouldUseProxy as A } from "@scalar/helpers/url/redirect-to-proxy";
|
|
5
|
+
import { encode as E, fromUint8Array as k } from "js-base64";
|
|
6
|
+
const S = (e) => {
|
|
7
|
+
if (!e?.url) return;
|
|
8
|
+
const s = Object.entries(e.variables ?? {}).reduce(
|
|
9
|
+
(i, [a, c]) => {
|
|
10
|
+
const h = c.value || c.default;
|
|
11
|
+
return h && (i[a] = h), i;
|
|
12
|
+
},
|
|
13
|
+
{}
|
|
14
|
+
);
|
|
15
|
+
return U(e.url, s);
|
|
16
|
+
}, w = (e) => {
|
|
17
|
+
const s = S(e);
|
|
18
|
+
return s ? b(s) ? typeof window > "u" ? {} : { basePath: s } : { baseUrl: s } : {};
|
|
19
|
+
}, C = () => {
|
|
9
20
|
const e = new Uint8Array(32);
|
|
10
21
|
return crypto.getRandomValues(e), k(e, !0);
|
|
11
|
-
},
|
|
12
|
-
if (
|
|
22
|
+
}, T = async (e, s) => {
|
|
23
|
+
if (s === "plain")
|
|
13
24
|
return e;
|
|
14
25
|
if (typeof crypto?.subtle?.digest != "function")
|
|
15
26
|
return console.warn("SHA-256 is only supported when using https, using a plain text code challenge instead."), e;
|
|
16
|
-
const
|
|
17
|
-
return k(new Uint8Array(
|
|
18
|
-
},
|
|
27
|
+
const a = new TextEncoder().encode(e), c = await crypto.subtle.digest("SHA-256", a);
|
|
28
|
+
return k(new Uint8Array(c), !0);
|
|
29
|
+
}, L = async (e, s, i) => {
|
|
19
30
|
try {
|
|
20
31
|
if (!e)
|
|
21
32
|
return [new Error("Flow not found"), null];
|
|
22
|
-
const
|
|
33
|
+
const a = e.selectedScopes.join(" ");
|
|
23
34
|
if (e.type === "clientCredentials" || e.type === "password")
|
|
24
|
-
return
|
|
35
|
+
return f(
|
|
25
36
|
e,
|
|
26
|
-
|
|
37
|
+
a,
|
|
27
38
|
{
|
|
28
|
-
proxyUrl:
|
|
39
|
+
proxyUrl: i
|
|
29
40
|
},
|
|
30
|
-
|
|
41
|
+
s
|
|
31
42
|
);
|
|
32
|
-
const
|
|
33
|
-
let
|
|
43
|
+
const c = (Math.random() + 1).toString(36).substring(2, 10), h = x(e.authorizationUrl, w(s)), t = new URL(h);
|
|
44
|
+
let g = null;
|
|
34
45
|
if (e.type === "implicit")
|
|
35
46
|
t.searchParams.set("response_type", "token");
|
|
36
47
|
else if (e.type === "authorizationCode" && (t.searchParams.set("response_type", "code"), e["x-usePkce"] !== "no")) {
|
|
37
|
-
const r =
|
|
38
|
-
|
|
48
|
+
const r = C(), n = await T(r, e["x-usePkce"]);
|
|
49
|
+
g = {
|
|
39
50
|
codeVerifier: r,
|
|
40
|
-
codeChallenge:
|
|
51
|
+
codeChallenge: n,
|
|
41
52
|
codeChallengeMethod: e["x-usePkce"] === "SHA-256" ? "S256" : "plain"
|
|
42
|
-
}, t.searchParams.set("code_challenge",
|
|
53
|
+
}, t.searchParams.set("code_challenge", n), t.searchParams.set("code_challenge_method", g.codeChallengeMethod);
|
|
43
54
|
}
|
|
44
55
|
if (e["x-scalar-redirect-uri"].startsWith("/")) {
|
|
45
|
-
const r =
|
|
46
|
-
t.searchParams.set("redirect_uri",
|
|
56
|
+
const r = S(s) || window.location.origin + window.location.pathname, n = x(e["x-scalar-redirect-uri"], { baseUrl: r });
|
|
57
|
+
t.searchParams.set("redirect_uri", n);
|
|
47
58
|
} else
|
|
48
59
|
t.searchParams.set("redirect_uri", e["x-scalar-redirect-uri"]);
|
|
49
60
|
e["x-scalar-security-query"] && Object.keys(e["x-scalar-security-query"]).forEach((r) => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
}), t.searchParams.set("client_id", e["x-scalar-client-id"]), t.searchParams.set("state",
|
|
53
|
-
const
|
|
54
|
-
return
|
|
55
|
-
const
|
|
56
|
-
let
|
|
61
|
+
const n = e["x-scalar-security-query"]?.[r];
|
|
62
|
+
n && t.searchParams.set(r, n);
|
|
63
|
+
}), t.searchParams.set("client_id", e["x-scalar-client-id"]), t.searchParams.set("state", c), a && t.searchParams.set("scope", a);
|
|
64
|
+
const o = window.open(t, "openAuth2Window", "left=100,top=100,width=800,height=600");
|
|
65
|
+
return o ? new Promise((r) => {
|
|
66
|
+
const n = setInterval(() => {
|
|
67
|
+
let p = null, d = null, u = null, y = null;
|
|
57
68
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
69
|
+
const l = new URL(o.location.href).searchParams, P = e["x-tokenName"] || "access_token";
|
|
70
|
+
p = l.get(P), d = l.get("code"), u = l.get("error"), y = l.get("error_description");
|
|
71
|
+
const _ = new URLSearchParams(o.location.href.split("#")[1]);
|
|
72
|
+
p ||= _.get(P), d ||= _.get("code"), u ||= _.get("error"), y ||= _.get("error_description");
|
|
62
73
|
} catch {
|
|
63
74
|
}
|
|
64
|
-
if (
|
|
65
|
-
if (clearInterval(
|
|
66
|
-
r([new Error(`OAuth error: ${
|
|
67
|
-
else if (
|
|
68
|
-
const
|
|
69
|
-
r(
|
|
70
|
-
} else d ? new URL(
|
|
75
|
+
if (o.closed || p || d || u)
|
|
76
|
+
if (clearInterval(n), o.close(), u)
|
|
77
|
+
r([new Error(`OAuth error: ${u}${y ? ` (${y})` : ""}`), null]);
|
|
78
|
+
else if (p) {
|
|
79
|
+
const l = o.location.href.match(/state=([^&]*)/)?.[1];
|
|
80
|
+
r(l === c ? [null, p] : [new Error("State mismatch"), null]);
|
|
81
|
+
} else d ? new URL(o.location.href).searchParams.get("state") === c ? f(
|
|
71
82
|
e,
|
|
72
|
-
|
|
83
|
+
a,
|
|
73
84
|
{
|
|
74
85
|
code: d,
|
|
75
|
-
pkce:
|
|
76
|
-
proxyUrl:
|
|
86
|
+
pkce: g,
|
|
87
|
+
proxyUrl: i
|
|
77
88
|
},
|
|
78
|
-
|
|
79
|
-
).then(r) : r([new Error("State mismatch"), null]) : (clearInterval(
|
|
89
|
+
s
|
|
90
|
+
).then(r) : r([new Error("State mismatch"), null]) : (clearInterval(n), r([new Error("Window was closed without granting authorization"), null]));
|
|
80
91
|
}, 200);
|
|
81
92
|
}) : [new Error("Failed to open auth window"), null];
|
|
82
93
|
} catch {
|
|
83
94
|
return [new Error("Failed to authorize oauth2 flow"), null];
|
|
84
95
|
}
|
|
85
|
-
},
|
|
86
|
-
code:
|
|
87
|
-
pkce:
|
|
88
|
-
proxyUrl:
|
|
89
|
-
} = {},
|
|
96
|
+
}, f = async (e, s, {
|
|
97
|
+
code: i,
|
|
98
|
+
pkce: a,
|
|
99
|
+
proxyUrl: c
|
|
100
|
+
} = {}, h) => {
|
|
90
101
|
if (!e)
|
|
91
102
|
return [new Error("OAuth2 flow was not defined"), null];
|
|
92
103
|
const t = new URLSearchParams();
|
|
93
|
-
t.set("client_id", e["x-scalar-client-id"]),
|
|
94
|
-
|
|
104
|
+
t.set("client_id", e["x-scalar-client-id"]), s && (e.type === "clientCredentials" || e.type === "password") && t.set("scope", s), e.clientSecret && (!e["x-scalar-credentials-location"] || e["x-scalar-credentials-location"] === "body") && t.set("client_secret", e.clientSecret), "x-scalar-redirect-uri" in e && e["x-scalar-redirect-uri"] && t.set("redirect_uri", e["x-scalar-redirect-uri"]), i ? (t.set("code", i), t.set("grant_type", "authorization_code"), a && t.set("code_verifier", a.codeVerifier)) : e.type === "password" ? (t.set("grant_type", "password"), t.set("username", e.username), t.set("password", e.password)) : t.set("grant_type", "client_credentials"), e["x-scalar-security-body"] && Object.entries(e["x-scalar-security-body"]).forEach(([m, o]) => {
|
|
105
|
+
o && t.set(m, o);
|
|
95
106
|
});
|
|
96
107
|
try {
|
|
97
|
-
const
|
|
108
|
+
const m = {
|
|
98
109
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
99
110
|
};
|
|
100
|
-
e.clientSecret && (!e["x-scalar-credentials-location"] || e["x-scalar-credentials-location"] === "header") && (
|
|
101
|
-
const r = x(e.tokenUrl, w(
|
|
111
|
+
e.clientSecret && (!e["x-scalar-credentials-location"] || e["x-scalar-credentials-location"] === "header") && (m.Authorization = `Basic ${E(`${e["x-scalar-client-id"]}:${e.clientSecret}`)}`);
|
|
112
|
+
const r = x(e.tokenUrl, w(h)), n = A(c, r) ? `${c}?${new URLSearchParams([["scalar_url", r]]).toString()}` : r, d = await (await fetch(n, {
|
|
102
113
|
method: "POST",
|
|
103
|
-
headers:
|
|
114
|
+
headers: m,
|
|
104
115
|
body: t
|
|
105
|
-
})).json(),
|
|
106
|
-
return [null, d[
|
|
116
|
+
})).json(), u = e["x-tokenName"] || "access_token";
|
|
117
|
+
return [null, d[u]];
|
|
107
118
|
} catch {
|
|
108
119
|
return [new Error("Failed to get an access token. Please check your credentials."), null];
|
|
109
120
|
}
|
|
110
121
|
};
|
|
111
122
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
L as authorizeOauth2,
|
|
124
|
+
f as authorizeServers,
|
|
125
|
+
T as generateCodeChallenge,
|
|
126
|
+
S as getInterpolatedServerUrl
|
|
115
127
|
};
|
package/package.json
CHANGED
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"rest",
|
|
19
19
|
"testing"
|
|
20
20
|
],
|
|
21
|
-
"version": "2.
|
|
21
|
+
"version": "2.32.0",
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
23
|
+
"node": ">=22"
|
|
24
24
|
},
|
|
25
25
|
"type": "module",
|
|
26
26
|
"main": "dist/index.js",
|
|
@@ -327,26 +327,26 @@
|
|
|
327
327
|
"whatwg-mimetype": "4.0.0",
|
|
328
328
|
"yaml": "^2.8.0",
|
|
329
329
|
"zod": "^4.3.5",
|
|
330
|
-
"@scalar/
|
|
331
|
-
"@scalar/
|
|
332
|
-
"@scalar/
|
|
333
|
-
"@scalar/
|
|
334
|
-
"@scalar/icons": "0.
|
|
335
|
-
"@scalar/import": "0.
|
|
336
|
-
"@scalar/
|
|
337
|
-
"@scalar/
|
|
338
|
-
"@scalar/
|
|
339
|
-
"@scalar/
|
|
340
|
-
"@scalar/openapi-
|
|
341
|
-
"@scalar/postman-to-openapi": "0.
|
|
342
|
-
"@scalar/sidebar": "0.
|
|
343
|
-
"@scalar/snippetz": "0.
|
|
344
|
-
"@scalar/
|
|
345
|
-
"@scalar/
|
|
346
|
-
"@scalar/use-
|
|
347
|
-
"@scalar/use-
|
|
348
|
-
"@scalar/
|
|
349
|
-
"@scalar/
|
|
330
|
+
"@scalar/components": "0.20.0",
|
|
331
|
+
"@scalar/draggable": "0.4.0",
|
|
332
|
+
"@scalar/helpers": "0.3.0",
|
|
333
|
+
"@scalar/analytics-client": "1.1.0",
|
|
334
|
+
"@scalar/icons": "0.6.0",
|
|
335
|
+
"@scalar/import": "0.5.0",
|
|
336
|
+
"@scalar/json-magic": "0.12.0",
|
|
337
|
+
"@scalar/object-utils": "1.3.0",
|
|
338
|
+
"@scalar/openapi-parser": "0.25.0",
|
|
339
|
+
"@scalar/oas-utils": "0.9.0",
|
|
340
|
+
"@scalar/openapi-types": "0.6.0",
|
|
341
|
+
"@scalar/postman-to-openapi": "0.5.0",
|
|
342
|
+
"@scalar/sidebar": "0.8.0",
|
|
343
|
+
"@scalar/snippetz": "0.7.0",
|
|
344
|
+
"@scalar/themes": "0.15.0",
|
|
345
|
+
"@scalar/types": "0.7.0",
|
|
346
|
+
"@scalar/use-hooks": "0.4.0",
|
|
347
|
+
"@scalar/use-codemirror": "0.14.0",
|
|
348
|
+
"@scalar/workspace-store": "0.36.0",
|
|
349
|
+
"@scalar/use-toasts": "0.10.0"
|
|
350
350
|
},
|
|
351
351
|
"devDependencies": {
|
|
352
352
|
"@tailwindcss/vite": "^4.1.18",
|
|
@@ -361,9 +361,9 @@
|
|
|
361
361
|
"vite": "^7.3.1",
|
|
362
362
|
"vite-svg-loader": "5.1.0",
|
|
363
363
|
"vitest": "4.0.16",
|
|
364
|
-
"@scalar/build-tooling": "0.
|
|
365
|
-
"@scalar/galaxy": "0.
|
|
366
|
-
"@scalar/pre-post-request-scripts": "0.
|
|
364
|
+
"@scalar/build-tooling": "0.5.0",
|
|
365
|
+
"@scalar/galaxy": "0.6.0",
|
|
366
|
+
"@scalar/pre-post-request-scripts": "0.3.0"
|
|
367
367
|
},
|
|
368
368
|
"scripts": {
|
|
369
369
|
"build": "scalar-build-vite",
|