UNPKG

@scalar/api-client

Version:

the open source API testing client

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