UNPKG

@scalar/api-client

Version:

the open source API testing client

247 lines (246 loc) 8.76 kB
import { defineComponent as T, createElementBlock as V, openBlock as d, Fragment as U, createBlock as k, createCommentVNode as w, createVNode as r, unref as a, withCtx as o, mergeProps as m, createTextVNode as u, createElementVNode as $, renderSlot as P } from "vue"; import { useLoadingState as A, ScalarButton as v } from "@scalar/components"; import { pkceOptions as B } from "@scalar/oas-utils/entities/spec"; import { useToasts as L } from "@scalar/use-toasts"; import { useWorkspace as R } from "../../../../store/store.js"; import { updateScheme as F } from "../helpers/update-scheme.js"; import I from "./OAuthScopesInput.vue.js"; import p from "./RequestAuthDataTableInput.vue.js"; import i from "../../../../components/DataTable/DataTableRow.vue.js"; import { authorizeOauth2 as N } from "../../libs/oauth2.js"; const O = { class: "flex h-8 items-center justify-end border-t" }, j = { class: "flex h-8 w-full items-center justify-end border-t" }, q = /* @__PURE__ */ T({ __name: "OAuth2", props: { collection: {}, environment: {}, envVariables: {}, flow: {}, persistAuth: { type: Boolean, default: !1 }, scheme: {}, server: {}, workspace: {} }, emits: ["authorized"], setup(s, { emit: z }) { const S = z, y = A(), { toast: g } = L(), b = R(), n = (l, e) => F(s.scheme.uid, l, e, b, s.persistAuth), C = async () => { if (y.isLoading || !s.collection?.uid) return; if (!s.server) { g("No server selected", "error"); return; } y.startLoading(); const [l, e] = await N( s.flow, s.server, s.workspace?.proxyUrl ).finally(() => y.stopLoading()); e ? (n(`flows.${s.flow.type}.token`, e), S("authorized")) : (console.error(l), g(l?.message ?? "Failed to authorize", "error")); }, f = { environment: s.environment, envVariables: s.envVariables, workspace: s.workspace }; return (l, e) => (d(), V(U, null, [ l.flow.token ? (d(), V(U, { key: 0 }, [ r(a(i), null, { default: o(() => [ r(p, m(f, { class: "border-r-transparent", modelValue: l.flow.token, placeholder: "QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT", type: "password", "onUpdate:modelValue": e[0] || (e[0] = (t) => n(`flows.${l.flow.type}.token`, t)) }), { default: o(() => [...e[10] || (e[10] = [ u(" Access Token ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }), r(a(i), { class: "min-w-full" }, { default: o(() => [ $("div", O, [ r(a(v), { class: "mr-1 p-0 px-2 py-0.5", loading: a(y), size: "sm", variant: "outlined", onClick: e[1] || (e[1] = (t) => n(`flows.${l.flow.type}.token`, "")) }, { default: o(() => [...e[11] || (e[11] = [ u(" Clear ", -1) ])]), _: 1 }, 8, ["loading"]), P(l.$slots, "oauth-actions") ]) ]), _: 3 }) ], 64)) : (d(), V(U, { key: 1 }, [ r(a(i), null, { default: o(() => [ "authorizationUrl" in l.flow ? (d(), k(p, m({ key: 0 }, f, { containerClass: "border-r-0", modelValue: l.flow.authorizationUrl, placeholder: "https://galaxy.scalar.com/authorize", "onUpdate:modelValue": e[2] || (e[2] = (t) => n(`flows.${l.flow.type}.authorizationUrl`, t)) }), { default: o(() => [...e[12] || (e[12] = [ u(" Auth URL ", -1) ])]), _: 1 }, 16, ["modelValue"])) : w("", !0), "tokenUrl" in l.flow ? (d(), k(p, m({ key: 1 }, f, { modelValue: l.flow.tokenUrl, placeholder: "https://galaxy.scalar.com/token", "onUpdate:modelValue": e[3] || (e[3] = (t) => n(`flows.${l.flow.type}.tokenUrl`, t)) }), { default: o(() => [...e[13] || (e[13] = [ u(" Token URL ", -1) ])]), _: 1 }, 16, ["modelValue"])) : w("", !0) ]), _: 1 }), "x-scalar-redirect-uri" in l.flow ? (d(), k(a(i), { key: 0 }, { default: o(() => [ r(p, m(f, { modelValue: l.flow["x-scalar-redirect-uri"], placeholder: "https://galaxy.scalar.com/callback", "onUpdate:modelValue": e[4] || (e[4] = (t) => n(`flows.${l.flow.type}.x-scalar-redirect-uri`, t)) }), { default: o(() => [...e[14] || (e[14] = [ u(" Redirect URL ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 })) : w("", !0), l.flow.type === "password" ? (d(), V(U, { key: 1 }, [ r(a(i), null, { default: o(() => [ r(p, m(f, { class: "text-c-2", modelValue: l.flow.username, placeholder: "janedoe", "onUpdate:modelValue": e[5] || (e[5] = (t) => n(`flows.${l.flow.type}.username`, t)) }), { default: o(() => [...e[15] || (e[15] = [ u(" Username ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }), r(a(i), null, { default: o(() => [ r(p, m(f, { modelValue: l.flow.password, placeholder: "********", type: "password", "onUpdate:modelValue": e[6] || (e[6] = (t) => n(`flows.${l.flow.type}.password`, t)) }), { default: o(() => [...e[16] || (e[16] = [ u(" Password ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }) ], 64)) : w("", !0), r(a(i), null, { default: o(() => [ r(p, m(f, { modelValue: l.flow["x-scalar-client-id"], placeholder: "12345", "onUpdate:modelValue": e[7] || (e[7] = (t) => n(`flows.${l.flow.type}.x-scalar-client-id`, t)) }), { default: o(() => [...e[17] || (e[17] = [ u(" Client ID ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }), "clientSecret" in l.flow ? (d(), k(a(i), { key: 2 }, { default: o(() => [ r(p, m(f, { modelValue: l.flow.clientSecret, placeholder: "XYZ123", type: "password", "onUpdate:modelValue": e[8] || (e[8] = (t) => n(`flows.${l.flow.type}.clientSecret`, t)) }), { default: o(() => [...e[18] || (e[18] = [ u(" Client Secret ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 })) : w("", !0), "x-usePkce" in l.flow ? (d(), k(a(i), { key: 3 }, { default: o(() => [ r(p, m(f, { enum: a(B), modelValue: l.flow["x-usePkce"], readOnly: "", "onUpdate:modelValue": e[9] || (e[9] = (t) => n( `flows.${l.flow.type}.x-usePkce`, t )) }), { default: o(() => [...e[19] || (e[19] = [ u(" Use PKCE ", -1) ])]), _: 1 }, 16, ["enum", "modelValue"]) ]), _: 1 })) : w("", !0), Object.keys(l.flow.scopes ?? {}).length ? (d(), k(a(i), { key: 4 }, { default: o(() => [ r(I, { flow: l.flow, updateScheme: n }, null, 8, ["flow"]) ]), _: 1 })) : w("", !0) ], 64)), l.flow.token ? w("", !0) : (d(), k(a(i), { key: 2, class: "min-w-full" }, { default: o(() => [ $("div", j, [ r(a(v), { class: "mr-0.75 p-0 px-2 py-0.5", loading: a(y), size: "sm", variant: "outlined", onClick: C }, { default: o(() => [...e[20] || (e[20] = [ u(" Authorize ", -1) ])]), _: 1 }, 8, ["loading"]) ]) ]), _: 1 })) ], 64)); } }); export { q as default };