@scalar/api-client
Version:
the open source API testing client
312 lines (311 loc) • 10.7 kB
JavaScript
import { defineComponent as P, computed as C, ref as R, watch as I, createElementBlock as p, openBlock as m, Fragment as V, createVNode as r, unref as o, withCtx as l, createTextVNode as d, createElementVNode as S, createBlock as f, createCommentVNode as v } from "vue";
import { useLoadingState as L, ScalarButton as k } from "@scalar/components";
import { pkceOptions as F } from "@scalar/oas-utils/entities/spec";
import { useToasts as A } from "@scalar/use-toasts";
import h from "./OAuthScopesInput.vue.js";
/* empty css */
import { authorizeOauth2 as N } from "../helpers/oauth.js";
import c from "./RequestAuthDataTableInput.vue.js";
import u from "../../../../components/DataTable/DataTableRow.vue.js";
const j = { class: "flex h-8 items-center justify-end gap-2 border-t" }, E = { class: "flex h-8 w-full items-center justify-end border-t" }, q = /* @__PURE__ */ P({
__name: "OAuth2",
props: {
environment: {},
flows: {},
type: {},
selectedScopes: {},
scheme: {},
server: {},
proxyUrl: {},
name: {},
eventBus: {}
},
emits: ["update:selectedScopes"],
setup(t, { emit: g }) {
const z = g, y = L(), { toast: B } = A(), a = C(() => t.flows[t.type]), U = C(
() => t.selectedScopes.filter((s) => s in (a.value.scopes ?? {}))
), x = (s) => {
if (t.scheme.type === "openIdConnect")
return i(s);
t.eventBus.emit("auth:update:security-scheme", {
payload: {
type: t.scheme.type,
flows: {
[t.type]: s
}
},
name: t.name
});
}, i = (s) => t.eventBus.emit("auth:update:security-scheme-secrets", {
payload: {
type: t.scheme.type,
[t.type]: s
},
name: t.name
}), T = () => t.eventBus.emit("auth:clear:security-scheme-secrets", {
name: t.name
}), w = R(!1);
I(
() => a.value["x-scalar-secret-redirect-uri"],
(s) => {
w.value || s || typeof window > "u" || !("x-scalar-secret-redirect-uri" in a.value) || (w.value = !0, i({
"x-scalar-secret-redirect-uri": window.location.origin + window.location.pathname
}));
},
{ immediate: !0 }
);
const b = async () => {
if (y.isLoading)
return;
y.start();
const [s, e] = await N(
t.flows,
t.type,
U.value,
t.server,
t.proxyUrl
);
await y.clear(), e ? i({ "x-scalar-secret-token": e }) : (console.error(s), B(s?.message ?? "Failed to authorize", "error"));
}, O = (s) => x({
"x-scalar-credentials-location": s === "body" ? "body" : "header"
});
return (s, e) => a.value["x-scalar-secret-token"] ? (m(), p(V, { key: 0 }, [
r(o(u), null, {
default: l(() => [
r(c, {
class: "border-r-transparent",
environment: t.environment,
modelValue: a.value["x-scalar-secret-token"],
placeholder: "QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT",
type: "password",
"onUpdate:modelValue": e[0] || (e[0] = (n) => i({ "x-scalar-secret-token": n }))
}, {
default: l(() => [...e[12] || (e[12] = [
d(" Access Token ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])
]),
_: 1
}),
r(o(u), { class: "min-w-full" }, {
default: l(() => [
S("div", j, [
r(o(k), {
class: "mr-1 p-0 px-2 py-0.5",
loader: o(y),
size: "sm",
variant: "outlined",
onClick: e[1] || (e[1] = () => i({ "x-scalar-secret-token": "" }))
}, {
default: l(() => [...e[13] || (e[13] = [
d(" Clear ", -1)
])]),
_: 1
}, 8, ["loader"])
])
]),
_: 1
})
], 64)) : (m(), p(V, { key: 1 }, [
r(o(u), null, {
default: l(() => [
"authorizationUrl" in a.value ? (m(), f(c, {
key: 0,
containerClass: "border-r-0",
environment: t.environment,
modelValue: a.value.authorizationUrl,
placeholder: "https://galaxy.scalar.com/authorize",
"onUpdate:modelValue": e[2] || (e[2] = (n) => x({ authorizationUrl: n }))
}, {
default: l(() => [...e[14] || (e[14] = [
d(" Auth URL ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])) : v("", !0),
"tokenUrl" in a.value ? (m(), f(c, {
key: 1,
environment: t.environment,
modelValue: a.value.tokenUrl,
placeholder: "https://galaxy.scalar.com/token",
"onUpdate:modelValue": e[3] || (e[3] = (n) => x({ tokenUrl: n }))
}, {
default: l(() => [...e[15] || (e[15] = [
d(" Token URL ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])) : v("", !0)
]),
_: 1
}),
"x-scalar-secret-redirect-uri" in a.value ? (m(), f(o(u), { key: 0 }, {
default: l(() => [
r(c, {
environment: t.environment,
modelValue: a.value["x-scalar-secret-redirect-uri"],
placeholder: "https://galaxy.scalar.com/callback",
"onUpdate:modelValue": e[4] || (e[4] = (n) => i({ "x-scalar-secret-redirect-uri": n }))
}, {
default: l(() => [...e[16] || (e[16] = [
d(" Redirect URL ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])
]),
_: 1
})) : v("", !0),
"x-scalar-secret-username" in a.value && "x-scalar-secret-password" in a.value ? (m(), p(V, { key: 1 }, [
r(o(u), null, {
default: l(() => [
r(c, {
class: "text-c-2",
environment: t.environment,
modelValue: a.value["x-scalar-secret-username"],
placeholder: "janedoe",
"onUpdate:modelValue": e[5] || (e[5] = (n) => i({ "x-scalar-secret-username": n }))
}, {
default: l(() => [...e[17] || (e[17] = [
d(" Username ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])
]),
_: 1
}),
r(o(u), null, {
default: l(() => [
r(c, {
environment: t.environment,
modelValue: a.value["x-scalar-secret-password"],
placeholder: "********",
type: "password",
"onUpdate:modelValue": e[6] || (e[6] = (n) => i({ "x-scalar-secret-password": n }))
}, {
default: l(() => [...e[18] || (e[18] = [
d(" Password ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])
]),
_: 1
})
], 64)) : v("", !0),
r(o(u), null, {
default: l(() => [
r(c, {
environment: t.environment,
modelValue: a.value["x-scalar-secret-client-id"],
placeholder: "12345",
"onUpdate:modelValue": e[7] || (e[7] = (n) => i({ "x-scalar-secret-client-id": n }))
}, {
default: l(() => [...e[19] || (e[19] = [
d(" Client ID ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])
]),
_: 1
}),
"x-scalar-secret-client-secret" in a.value ? (m(), f(o(u), { key: 2 }, {
default: l(() => [
r(c, {
environment: t.environment,
modelValue: a.value["x-scalar-secret-client-secret"],
placeholder: "XYZ123",
type: "password",
"onUpdate:modelValue": e[8] || (e[8] = (n) => i({ "x-scalar-secret-client-secret": n }))
}, {
default: l(() => [...e[20] || (e[20] = [
d(" Client Secret ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])
]),
_: 1
})) : v("", !0),
"x-usePkce" in a.value ? (m(), f(o(u), { key: 3 }, {
default: l(() => [
r(c, {
enum: o(F),
environment: t.environment,
modelValue: a.value["x-usePkce"],
readOnly: "",
"onUpdate:modelValue": e[9] || (e[9] = (n) => x({
"x-usePkce": n
}))
}, {
default: l(() => [...e[21] || (e[21] = [
d(" Use PKCE ", -1)
])]),
_: 1
}, 8, ["enum", "environment", "modelValue"])
]),
_: 1
})) : v("", !0),
t.type !== "implicit" ? (m(), f(o(u), { key: 4 }, {
default: l(() => [
r(c, {
enum: ["header", "body"],
environment: t.environment,
modelValue: a.value["x-scalar-credentials-location"] || "header",
placeholder: "header",
readOnly: "",
"onUpdate:modelValue": e[10] || (e[10] = (n) => O(n))
}, {
default: l(() => [...e[22] || (e[22] = [
d(" Credentials Location ", -1)
])]),
_: 1
}, 8, ["environment", "modelValue"])
]),
_: 1
})) : v("", !0),
r(o(u), null, {
default: l(() => [
r(h, {
flow: a.value,
flowType: t.type,
selectedScopes: U.value,
"onUpdate:selectedScopes": e[11] || (e[11] = (n) => z("update:selectedScopes", n))
}, null, 8, ["flow", "flowType", "selectedScopes"])
]),
_: 1
}),
r(o(u), { class: "min-w-full" }, {
default: l(() => [
S("div", E, [
t.scheme.type === "openIdConnect" ? (m(), f(o(k), {
key: 0,
class: "mr-1 p-0 px-2 py-0.5",
loader: o(y),
size: "sm",
variant: "outlined",
onClick: T
}, {
default: l(() => [...e[23] || (e[23] = [
d(" Clear ", -1)
])]),
_: 1
}, 8, ["loader"])) : v("", !0),
r(o(k), {
class: "mr-0.75 p-0 px-2 py-0.5",
loader: o(y),
size: "sm",
variant: "outlined",
onClick: b
}, {
default: l(() => [...e[24] || (e[24] = [
d(" Authorize ", -1)
])]),
_: 1
}, 8, ["loader"])
])
]),
_: 1
})
], 64));
}
});
export {
q as default
};