UNPKG

@scalar/api-client

Version:

the open source API testing client

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