@scalar/api-client 3.21.4 → 3.21.5

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/plugins/posthog/sanitize-event-payload.d.ts.map +1 -1
  3. package/dist/plugins/posthog/sanitize-event-payload.js +1 -0
  4. package/dist/plugins/posthog/sanitize-event-payload.js.map +1 -1
  5. package/dist/style.css +59 -49
  6. package/dist/v2/blocks/operation-block/OperationBlock.vue.d.ts.map +1 -1
  7. package/dist/v2/blocks/operation-block/OperationBlock.vue.js.map +1 -1
  8. package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js +1 -1
  9. package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js.map +1 -1
  10. package/dist/v2/blocks/request-block/RequestBlock.vue.script.js.map +1 -1
  11. package/dist/v2/blocks/request-block/components/RequestBody.vue.d.ts.map +1 -1
  12. package/dist/v2/blocks/request-block/components/RequestBody.vue.js +1 -1
  13. package/dist/v2/blocks/request-block/components/RequestBody.vue.js.map +1 -1
  14. package/dist/v2/blocks/request-block/components/RequestBody.vue.script.js +1 -1
  15. package/dist/v2/blocks/request-block/components/RequestBody.vue.script.js.map +1 -1
  16. package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.d.ts.map +1 -1
  17. package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.js +1 -1
  18. package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.js.map +1 -1
  19. package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.script.js +1 -1
  20. package/dist/v2/blocks/scalar-address-bar-block/components/AddressBarHistory.vue.script.js.map +1 -1
  21. package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.script.js.map +1 -1
  22. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.d.ts.map +1 -1
  23. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.js.map +1 -1
  24. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js +53 -22
  25. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js.map +1 -1
  26. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTableInput.vue.d.ts +4 -0
  27. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTableInput.vue.d.ts.map +1 -1
  28. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTableInput.vue.js.map +1 -1
  29. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTableInput.vue.script.js +23 -12
  30. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthDataTableInput.vue.script.js.map +1 -1
  31. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.d.ts.map +1 -1
  32. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.js.map +1 -1
  33. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.script.js +30 -6
  34. package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.script.js.map +1 -1
  35. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.d.ts.map +1 -1
  36. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.js +3 -1
  37. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.js.map +1 -1
  38. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts.map +1 -1
  39. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js +9 -3
  40. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js.map +1 -1
  41. package/dist/v2/components/code-input/CodeInput.vue.d.ts.map +1 -1
  42. package/dist/v2/components/code-input/CodeInput.vue.js +1 -1
  43. package/dist/v2/components/code-input/CodeInput.vue.js.map +1 -1
  44. package/dist/v2/components/code-input/CodeInput.vue.script.js.map +1 -1
  45. package/dist/v2/components/data-table/DataTableInput.vue.d.ts.map +1 -1
  46. package/dist/v2/components/data-table/DataTableInput.vue.js +1 -1
  47. package/dist/v2/components/data-table/DataTableInput.vue.js.map +1 -1
  48. package/dist/v2/components/data-table/DataTableInput.vue.script.js +15 -11
  49. package/dist/v2/components/data-table/DataTableInput.vue.script.js.map +1 -1
  50. package/dist/v2/components/server/ServerDropdown.vue.d.ts.map +1 -1
  51. package/dist/v2/components/server/ServerDropdown.vue.js.map +1 -1
  52. package/dist/v2/components/server/ServerDropdown.vue.script.js +1 -1
  53. package/dist/v2/components/server/ServerDropdown.vue.script.js.map +1 -1
  54. package/dist/v2/constants.js +1 -1
  55. package/dist/v2/features/localization/locales/ar.d.ts +3 -0
  56. package/dist/v2/features/localization/locales/ar.d.ts.map +1 -1
  57. package/dist/v2/features/localization/locales/ar.js +4 -1
  58. package/dist/v2/features/localization/locales/ar.js.map +1 -1
  59. package/dist/v2/features/localization/locales/de.d.ts +3 -0
  60. package/dist/v2/features/localization/locales/de.d.ts.map +1 -1
  61. package/dist/v2/features/localization/locales/de.js +4 -1
  62. package/dist/v2/features/localization/locales/de.js.map +1 -1
  63. package/dist/v2/features/localization/locales/es.d.ts +3 -0
  64. package/dist/v2/features/localization/locales/es.d.ts.map +1 -1
  65. package/dist/v2/features/localization/locales/es.js +4 -1
  66. package/dist/v2/features/localization/locales/es.js.map +1 -1
  67. package/dist/v2/features/localization/locales/fr.d.ts +3 -0
  68. package/dist/v2/features/localization/locales/fr.d.ts.map +1 -1
  69. package/dist/v2/features/localization/locales/fr.js +4 -1
  70. package/dist/v2/features/localization/locales/fr.js.map +1 -1
  71. package/dist/v2/features/localization/locales/pt.d.ts +3 -0
  72. package/dist/v2/features/localization/locales/pt.d.ts.map +1 -1
  73. package/dist/v2/features/localization/locales/pt.js +4 -1
  74. package/dist/v2/features/localization/locales/pt.js.map +1 -1
  75. package/dist/v2/features/localization/locales/ru.d.ts +3 -0
  76. package/dist/v2/features/localization/locales/ru.d.ts.map +1 -1
  77. package/dist/v2/features/localization/locales/ru.js +4 -1
  78. package/dist/v2/features/localization/locales/ru.js.map +1 -1
  79. package/dist/v2/features/localization/locales/zh-cn.d.ts +3 -0
  80. package/dist/v2/features/localization/locales/zh-cn.d.ts.map +1 -1
  81. package/dist/v2/features/localization/locales/zh-cn.js +4 -1
  82. package/dist/v2/features/localization/locales/zh-cn.js.map +1 -1
  83. package/dist/v2/features/localization/translations.d.ts +3 -0
  84. package/dist/v2/features/localization/translations.d.ts.map +1 -1
  85. package/dist/v2/features/localization/translations.js +4 -1
  86. package/dist/v2/features/localization/translations.js.map +1 -1
  87. package/dist/v2/workspace-events.d.ts.map +1 -1
  88. package/dist/v2/workspace-events.js +1 -0
  89. package/dist/v2/workspace-events.js.map +1 -1
  90. package/dist/vue-styles.css +29 -31
  91. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"RequestAuthTab.vue.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { useLoadingState } from '@scalar/components/loading'\nimport { ScalarMarkdownSummary } from '@scalar/components/markdown'\nimport { ScalarModal, useModal } from '@scalar/components/modal'\nimport { ScalarIconGear } from '@scalar/icons'\nimport { useToasts } from '@scalar/use-toasts'\nimport type {\n SecretsApiKey,\n SecretsHttp,\n} from '@scalar/workspace-store/entities/auth'\nimport type {\n ApiReferenceEvents,\n WorkspaceEventBus,\n} from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n getEnvironmentVariables,\n type MergedSecuritySchemes,\n type OAuthFlowsObjectSecret,\n type SecuritySchemeObjectSecret,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { getDocumentTypeLabel } from '@scalar/workspace-store/schemas/type-guards'\nimport type {\n ApiKeyObject,\n SecurityRequirementObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { capitalize, computed, ref } from 'vue'\n\nimport { refreshOauth2Token } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth'\nimport { getVisibleOrderedFlowKeys } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth-flows'\nimport {\n runOAuth2Authorize,\n storeOAuth2Tokens,\n} from '@/v2/blocks/scalar-auth-selector-block/helpers/run-oauth2-authorize'\nimport { getOauth2AcquisitionTarget } from '@/v2/blocks/scalar-auth-selector-block/helpers/security-scheme'\nimport {\n DataTable,\n DataTableCell,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport OAuth2, { type OAuth2Options } from './OAuth2.vue'\nimport OAuth2Metadata from './OAuth2Metadata.vue'\nimport OpenIDConnect from './OpenIDConnect.vue'\nimport RequestAuthDataTableInput from './RequestAuthDataTableInput.vue'\n\nconst {\n environment,\n isStatic,\n proxyUrl,\n selectedSecuritySchemas,\n securitySchemes,\n server,\n eventBus,\n options,\n documentType = 'openapi',\n} = defineProps<{\n /** Current environment configuration */\n environment: XScalarEnvironment\n /** Controls the display of certain borders which are used when we are non-collapsible */\n isStatic: boolean\n /** Proxy URL */\n proxyUrl: string\n /** Selected security schemes*/\n selectedSecuritySchemas: SecurityRequirementObject\n /** Merged security schemes from the document and the config together with the auth store secrets */\n securitySchemes: MergedSecuritySchemes\n /** Current server configuration */\n server: ServerObject | null\n /** Event bus for authentication updates */\n eventBus: WorkspaceEventBus\n /** Any config options required for the OAuth2 flow */\n options?: OAuth2Options\n /** Type of the document the schemes belong to, used to label the missing-type warning */\n documentType?: 'openapi' | 'asyncapi'\n}>()\n\nconst emits = defineEmits<{\n (\n e: 'update:selectedScopes',\n payload: Omit<ApiReferenceEvents['auth:update:selected-scopes'], 'meta'>,\n ): void\n (e: 'upsert:scope', payload: ApiReferenceEvents['auth:upsert:scopes']): void\n (e: 'delete:scope', payload: ApiReferenceEvents['auth:delete:scopes']): void\n}>()\n\nconst { translate } = useLocalization()\n\ntype SecurityItem = {\n scheme: SecuritySchemeObjectSecret | undefined\n name: string\n scopes: string[]\n /** Ordered, non-hidden oauth2/openIdConnect flow keys for this scheme (empty for other types). */\n visibleFlowKeys: (keyof OAuthFlowsObjectSecret)[]\n}\n\n/**\n * Human-readable name of the document type.\n * Used in the missing-type warning so it points at the correct document\n * (e.g. \"AsyncAPI\") instead of always naming OpenAPI.\n */\nconst documentTypeLabel = computed<string>(() =>\n getDocumentTypeLabel(documentType),\n)\n\n/**\n * Resolves security schemes from the OpenAPI document and combines them with their selected scopes.\n * Each item includes the scheme definition, name, and associated scopes.\n */\nconst security = computed<SecurityItem[]>(() =>\n Object.entries(selectedSecuritySchemas).map(([name, scopes = []]) => {\n const scheme = getResolvedRef(securitySchemes[name])\n return {\n scheme,\n name,\n scopes,\n // Compute the visible, ordered flow keys once per scheme so the tabs, the label, and the\n // active-flow tracking all agree on the same set (and we do not filter + sort on every access).\n visibleFlowKeys:\n scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\n ? getVisibleOrderedFlowKeys(scheme.flows)\n : [],\n }\n }),\n)\n\n/** Tracks which OAuth2 flow is currently active when multiple flows are available. */\nconst activeFlow = ref<string>('')\n\n/**\n * Keeps the selected flow in sync with the currently visible flow keys. Validating against the\n * visible set (not every declared flow) means a selection that becomes hidden — e.g. the document\n * is updated to mark the active flow with `x-scalar-ignore` — resets, so the default (first visible)\n * flow activates instead of leaving no tab selected.\n */\nconst selectedFlow = computed<string>(() => {\n const visibleFlowKeys = security.value.flatMap((item) => item.visibleFlowKeys)\n\n return visibleFlowKeys.some((key) => key === activeFlow.value)\n ? activeFlow.value\n : ''\n})\n\nconst setActiveFlow = (flow: string): void => {\n activeFlow.value = flow\n}\n\n/** Determines if multiple auth schemes are configured, which affects the UI layout. */\nconst hasMultipleSchemes = computed<boolean>(() => security.value.length > 1)\n\n/**\n * Generates a human-readable label for the security scheme.\n * Intentionally omits the description here — it is rendered separately as\n * rich text via ScalarMarkdownSummary so markdown formatting is preserved.\n */\nconst generateLabel = (\n name: string,\n scheme: SecuritySchemeObjectSecret,\n): string => {\n const capitalizedName = capitalize(name)\n\n switch (scheme.type) {\n case 'apiKey':\n return `${capitalizedName}: ${scheme.in}`\n\n case 'openIdConnect':\n case 'oauth2': {\n const firstFlow = getVisibleOrderedFlowKeys(scheme.flows)[0]\n const currentFlow = selectedFlow.value || firstFlow\n if (!currentFlow) {\n return capitalizedName\n }\n return `${capitalizedName}: ${currentFlow}`\n }\n\n case 'http':\n return `${capitalizedName}: ${scheme.scheme}`\n\n default:\n return capitalizedName\n }\n}\n\n/**\n * Whether an API key scheme exposes an editable parameter name.\n *\n * OpenAPI `apiKey` and AsyncAPI `httpApiKey` (normalized to `apiKey`) name a query/header/cookie\n * parameter, so the Name input is shown. AsyncAPI `apiKey` places the key in the broker `user` or\n * `password` slot and has no parameter name, so the Name input is hidden and only the value is asked for.\n */\nconst apiKeyHasName = (scheme: { in?: string }): boolean =>\n scheme.in !== 'user' && scheme.in !== 'password'\n\n/**\n * The scheme's type when it is one we do not render inputs for (a type outside both the OpenAPI\n * and AsyncAPI security scheme unions). Read through a helper so the fallback template branch,\n * where the scheme type is narrowed to `never` after the supported cases, can still surface the type.\n */\nconst getUnsupportedSchemeType = (\n scheme: SecurityItem['scheme'],\n): string | undefined => scheme?.type\n\n/**\n * Determines if an OAuth2 flow tab should be active.\n * The first flow is active by default if no flow is explicitly selected.\n */\nconst isFlowActive = (flowKey: string, index: number): boolean =>\n selectedFlow.value === flowKey || (index === 0 && !selectedFlow.value)\n\n/** Computes the container class for static display mode. */\nconst getStaticBorderClass = (): string | false => isStatic && 'border-t'\n\nconst handleHttpSecretsUpdate = (\n payload: Omit<Partial<SecretsHttp>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'http', ...payload },\n name,\n })\n\nconst handleApiKeySecretsUpdate = (\n payload: Omit<Partial<SecretsApiKey>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\nconst handleApiKeySecuritySchemeUpdate = (\n payload: Omit<Partial<ApiKeyObject>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\n/** Handles scope selection updates for OAuth2 */\nconst handleScopesUpdate = (\n name: string,\n event: { scopes?: string[]; scope?: string; selected?: boolean },\n): void => {\n emits('update:selectedScopes', {\n id: Object.keys(selectedSecuritySchemas),\n name,\n ...event,\n })\n}\n\n/** Handles scope-definition upserts (add / rename / description change) */\nconst handleScopeUpsert = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:upsert:scopes'], 'name'>,\n): void => {\n emits('upsert:scope', { ...event, name })\n}\n\n/** Handles scope-definition deletes */\nconst handleScopeDelete = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:delete:scopes'], 'name'>,\n): void => {\n emits('delete:scope', { ...event, name })\n}\n\n/**\n * Computes dynamic classes for OAuth2 flow tabs based on active state.\n */\nconst getFlowTabClasses = (flowKey: string, index: number): string => {\n const baseClasses =\n 'floating-bg text-c-3 relative cursor-pointer border-b border-transparent py-1 text-base font-medium'\n const activeClasses = '!text-c-1 !rounded-none border-b !border-current'\n\n return isFlowActive(flowKey, index)\n ? `${baseClasses} ${activeClasses} ${isStatic ? 'opacity-100' : ''}`\n : baseClasses\n}\n\n/**\n * OAuth2 token-acquisition target (an oauth2 scheme with an interactive grant) sourced from\n * the merged schemes. When the active scheme is HTTP bearer, this powers the inline\n * \"Authorize via OAuth2\" shortcut: the flow's bearer token is written onto the bearer scheme,\n * so the panel never switches to oauth2.\n *\n * The shortcut is purely a convenience, so it is offered for any interactive oauth2 scheme —\n * including one that is also independently selectable in the dropdown (e.g. Scalar Galaxy's\n * `oAuth2`). Whether that oauth2 scheme is *hidden* from the dropdown is a separate decision made\n * in the selector; here we only surface the shortcut.\n */\nconst oauth2Target = computed(() => getOauth2AcquisitionTarget(securitySchemes))\n\n/** Resolved oauth2 scheme object, for embedding its config form behind the gear. */\nconst oauth2Scheme = computed(() =>\n oauth2Target.value\n ? getResolvedRef(securitySchemes[oauth2Target.value.name])\n : undefined,\n)\n\nconst acquisitionLoader = useLoadingState()\nconst { toast } = useToasts()\nconst configModal = useModal()\n/** Bearer scheme that opened the config modal, so its Authorize callback targets it. */\nconst configBearerName = ref<string | undefined>()\n\n/** Runs the OAuth2 flow and writes the resulting bearer token onto the bearer scheme. */\nconst handleAcquisitionAuthorize = async (\n bearerName: string,\n): Promise<void> => {\n const target = oauth2Target.value\n if (!target || acquisitionLoader.isLoading) {\n return\n }\n acquisitionLoader.start()\n const [error] = await runOAuth2Authorize({\n eventBus,\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flows: target.flows,\n flowType: target.flowType,\n scopes: target.scopes,\n server,\n proxyUrl,\n environment,\n options,\n })\n await acquisitionLoader.clear()\n if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToauthorize'),\n 'error',\n )\n }\n}\n\n/** Refreshes the OAuth2 token and rewrites it onto the bearer scheme. */\nconst handleAcquisitionRefresh = async (bearerName: string): Promise<void> => {\n const target = oauth2Target.value\n // Only the authorization-code flow carries a refresh token; implicit can't be refreshed.\n if (\n !target ||\n target.flowType !== 'authorizationCode' ||\n acquisitionLoader.isLoading\n ) {\n return\n }\n acquisitionLoader.start()\n const [error, tokens] = await refreshOauth2Token(\n target.flows,\n target.flowType,\n proxyUrl,\n server,\n getEnvironmentVariables(environment),\n options?.customFetch,\n )\n await acquisitionLoader.clear()\n if (tokens?.accessToken) {\n storeOAuth2Tokens(eventBus, {\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flowType: target.flowType,\n tokens,\n })\n } else if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToRefresh'),\n 'error',\n )\n }\n}\n\nconst openAcquisitionConfig = (bearerName: string): void => {\n configBearerName.value = bearerName\n configModal.show()\n}\n\n/** Closes the config modal and runs Authorize against the bearer scheme that opened it. */\nconst handleConfigAuthorize = (): void => {\n const bearerName = configBearerName.value\n configModal.hide()\n if (bearerName) {\n void handleAcquisitionAuthorize(bearerName)\n }\n}\n</script>\n<template>\n <template\n v-for=\"{ scheme, name, scopes, visibleFlowKeys } in security\"\n :key=\"name\">\n <!--\n Header row for AND'ed schemes: label (bold) and description (rich text) are\n combined.\n -->\n <DataTableRow v-if=\"hasMultipleSchemes && scheme\">\n <DataTableCell\n :aria-label=\"generateLabel(name, scheme)\"\n class=\"max-h-[auto]\">\n <div class=\"bg-b-1 min-w-0 flex-1 px-3 py-1.25\">\n <p class=\"text-c-1 leading-5.5 font-medium\">\n {{ generateLabel(name, scheme) }}\n </p>\n <ScalarMarkdownSummary\n v-if=\"scheme.description\"\n class=\"auth-description text-c-2 w-full\"\n :value=\"scheme.description\" />\n </div>\n </DataTableCell>\n </DataTableRow>\n\n <!-- Description: shown for single auth schemes with descriptions -->\n <DataTableRow v-if=\"scheme?.description && !hasMultipleSchemes\">\n <DataTableCell\n :aria-label=\"scheme.description\"\n class=\"max-h-[auto]\">\n <ScalarMarkdownSummary\n class=\"auth-description bg-b-1 text-c-2 min-w-0 flex-1 px-3 py-1.25\"\n :value=\"scheme.description\" />\n </DataTableCell>\n </DataTableRow>\n\n <!-- HTTP Authentication -->\n <template v-if=\"scheme?.type === 'http'\">\n <!-- Bearer Token -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer'\">\n <RequestAuthDataTableInput\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n :placeholder=\"translate('apiClient.requestAuthTab.token')\"\n type=\"password\"\n @update:modelValue=\"\n (v) => handleHttpSecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.bearerToken') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n\n <!-- OAuth2 token-acquisition shortcut (shown when an interactive oauth2 flow exists) -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer' && oauth2Target\">\n <div class=\"flex h-8 items-center gap-2 border-t px-3\">\n <span class=\"text-c-3 mr-auto text-xs\">{{\n translate('apiClient.requestAuthTab.getAToken')\n }}</span>\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n type=\"button\"\n variant=\"outlined\"\n @click=\"handleAcquisitionAuthorize(name)\">\n {{\n translate('apiClient.requestAuthTab.authorizeVia', {\n name: oauth2Target.name,\n })\n }}\n </ScalarButton>\n <ScalarButton\n v-if=\"\n scheme['x-scalar-secret-token'] &&\n oauth2Target.flowType === 'authorizationCode'\n \"\n class=\"p-0 px-2 py-0.5\"\n :disabled=\"acquisitionLoader.isLoading\"\n size=\"sm\"\n type=\"button\"\n variant=\"outlined\"\n @click=\"handleAcquisitionRefresh(name)\">\n {{ translate('apiClient.requestAuthTab.refresh') }}\n </ScalarButton>\n <ScalarIconButton\n :icon=\"ScalarIconGear\"\n :label=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \"\n size=\"xs\"\n @click=\"openAcquisitionConfig(name)\" />\n </div>\n </DataTableRow>\n\n <!-- HTTP Basic Authentication -->\n <template v-else-if=\"scheme?.scheme === 'basic'\">\n <DataTableRow>\n <RequestAuthDataTableInput\n class=\"text-c-2\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-username']\"\n placeholder=\"janedoe\"\n required\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-username': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.username') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n :environment\n :modelValue=\"scheme['x-scalar-secret-password']\"\n placeholder=\"********\"\n type=\"password\"\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-password': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.password') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n </template>\n\n <!-- API Key Authentication -->\n <template v-else-if=\"scheme?.type === 'apiKey'\">\n <DataTableRow v-if=\"apiKeyHasName(scheme)\">\n <RequestAuthDataTableInput\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme.name ?? ''\"\n placeholder=\"api-key\"\n @update:modelValue=\"\n (v) => handleApiKeySecuritySchemeUpdate({ name: v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.name') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n :containerClass=\"\n apiKeyHasName(scheme) ? undefined : getStaticBorderClass()\n \"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n placeholder=\"QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT\"\n type=\"password\"\n @update:modelValue=\"\n (v) =>\n handleApiKeySecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.value') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n\n <!-- OAuth 2.0 / OpenID Connect Authentication -->\n <template\n v-else-if=\"scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\">\n <OAuth2Metadata\n v-if=\"\n scheme.type === 'oauth2' && (!isStatic || scheme.oauth2MetadataUrl)\n \"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :name\n :proxyUrl\n :scheme />\n\n <!-- OpenID Connect -->\n <OpenIDConnect\n v-if=\"scheme?.type === 'openIdConnect' && !visibleFlowKeys.length\"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :getStaticBorderClass\n :name\n :proxyUrl\n :scheme />\n\n <!-- Flow selector tabs: shown when multiple visible flows are available -->\n <DataTableRow v-if=\"visibleFlowKeys.length > 1\">\n <div class=\"flex min-h-8 border-t text-base\">\n <div class=\"flex h-8 max-w-full gap-2.5 overflow-x-auto px-3\">\n <button\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\"\n :class=\"getFlowTabClasses(key, ind)\"\n type=\"button\"\n @click=\"setActiveFlow(key)\">\n <span class=\"relative z-10\">{{ key }}</span>\n </button>\n </div>\n </div>\n </DataTableRow>\n\n <!-- OAuth2 flow configuration -->\n <template\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\">\n <OAuth2\n v-if=\"scheme.flows && isFlowActive(key, ind)\"\n :environment\n :eventBus\n :flows=\"scheme.flows\"\n :name\n :options\n :proxyUrl\n :scheme\n :selectedScopes=\"scopes\"\n :server\n :type=\"key\"\n @delete:scope=\"(event) => handleScopeDelete(name, event)\"\n @update:selectedScopes=\"(event) => handleScopesUpdate(name, event)\"\n @upsert:scope=\"(event) => handleScopeUpsert(name, event)\" />\n </template>\n </template>\n\n <!-- Browser WebSocket connections cannot apply these broker credentials. -->\n <div\n v-else-if=\"\n scheme?.type === 'userPassword' ||\n scheme?.type === 'plain' ||\n scheme?.type === 'scramSha256' ||\n scheme?.type === 'scramSha512' ||\n scheme?.type === 'X509' ||\n scheme?.type === 'symmetricEncryption' ||\n scheme?.type === 'asymmetricEncryption' ||\n scheme?.type === 'gssapi'\n \"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.unsupportedCredentials') }}\n </div>\n\n <!-- Mutual TLS credentials are chosen during the browser-managed TLS handshake. -->\n <div\n v-else-if=\"scheme?.type === 'mutualTLS'\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.mutualTlsHint') }}\n </div>\n\n <!-- Scheme has a type we do not render inputs for -->\n <div\n v-else-if=\"getUnsupportedSchemeType(scheme)\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.unsupportedType', {\n type: getUnsupportedSchemeType(scheme) ?? '',\n })\n }}\n </div>\n\n <!-- Scheme is missing type -->\n <div\n v-else\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.missingType', {\n type: documentTypeLabel,\n })\n }}\n </div>\n </template>\n\n <!-- OAuth2 configuration modal (opened from the bearer scheme's gear) -->\n <ScalarModal\n v-if=\"oauth2Target && oauth2Scheme\"\n size=\"sm\"\n :state=\"configModal\"\n :title=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \">\n <DataTable\n :columns=\"['']\"\n presentational>\n <OAuth2\n :environment\n :eventBus\n :flows=\"oauth2Target.flows\"\n hideActions\n :name=\"oauth2Target.name\"\n :options\n :proxyUrl\n :scheme=\"oauth2Scheme\"\n :selectedScopes=\"oauth2Target.scopes\"\n :server\n :type=\"oauth2Target.flowType\"\n @delete:scope=\"(event) => handleScopeDelete(oauth2Target!.name, event)\"\n @update:selectedScopes=\"\n (event) => handleScopesUpdate(oauth2Target!.name, event)\n \"\n @upsert:scope=\"\n (event) => handleScopeUpsert(oauth2Target!.name, event)\n \" />\n </DataTable>\n <div class=\"flex h-8 items-center justify-end gap-2 border-t\">\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"configModal.hide()\">\n {{ translate('apiClient.requestAuthTab.cancel') }}\n </ScalarButton>\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n @click=\"handleConfigAuthorize\">\n {{ translate('apiClient.requestAuthTab.authorize') }}\n </ScalarButton>\n </div>\n </ScalarModal>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"RequestAuthTab.vue.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { useLoadingState } from '@scalar/components/loading'\nimport { ScalarMarkdownSummary } from '@scalar/components/markdown'\nimport { ScalarModal, useModal } from '@scalar/components/modal'\nimport { ScalarIconGear } from '@scalar/icons'\nimport { useToasts } from '@scalar/use-toasts'\nimport type {\n SecretsApiKey,\n SecretsHttp,\n} from '@scalar/workspace-store/entities/auth'\nimport type {\n ApiReferenceEvents,\n WorkspaceEventBus,\n} from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n getEnvironmentVariables,\n type MergedSecuritySchemes,\n type OAuthFlowsObjectSecret,\n type SecuritySchemeObjectSecret,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { getDocumentTypeLabel } from '@scalar/workspace-store/schemas/type-guards'\nimport type {\n ApiKeyObject,\n SecurityRequirementObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { capitalize, computed, ref } from 'vue'\n\nimport { refreshOauth2Token } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth'\nimport { getVisibleOrderedFlowKeys } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth-flows'\nimport {\n runOAuth2Authorize,\n storeOAuth2Tokens,\n} from '@/v2/blocks/scalar-auth-selector-block/helpers/run-oauth2-authorize'\nimport { getOauth2AcquisitionTarget } from '@/v2/blocks/scalar-auth-selector-block/helpers/security-scheme'\nimport {\n DataTable,\n DataTableCell,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport OAuth2, { type OAuth2Options } from './OAuth2.vue'\nimport OAuth2Metadata from './OAuth2Metadata.vue'\nimport OpenIDConnect from './OpenIDConnect.vue'\nimport RequestAuthDataTableInput from './RequestAuthDataTableInput.vue'\n\nconst {\n environment,\n isStatic,\n proxyUrl,\n selectedSecuritySchemas,\n securitySchemes,\n server,\n eventBus,\n options,\n documentType = 'openapi',\n} = defineProps<{\n /** Current environment configuration */\n environment: XScalarEnvironment\n /** Controls the display of certain borders which are used when we are non-collapsible */\n isStatic: boolean\n /** Proxy URL */\n proxyUrl: string\n /** Selected security schemes*/\n selectedSecuritySchemas: SecurityRequirementObject\n /** Merged security schemes from the document and the config together with the auth store secrets */\n securitySchemes: MergedSecuritySchemes\n /** Current server configuration */\n server: ServerObject | null\n /** Event bus for authentication updates */\n eventBus: WorkspaceEventBus\n /** Any config options required for the OAuth2 flow */\n options?: OAuth2Options\n /** Type of the document the schemes belong to, used to label the missing-type warning */\n documentType?: 'openapi' | 'asyncapi'\n}>()\n\nconst emits = defineEmits<{\n (\n e: 'update:selectedScopes',\n payload: Omit<ApiReferenceEvents['auth:update:selected-scopes'], 'meta'>,\n ): void\n (e: 'upsert:scope', payload: ApiReferenceEvents['auth:upsert:scopes']): void\n (e: 'delete:scope', payload: ApiReferenceEvents['auth:delete:scopes']): void\n}>()\n\nconst { translate } = useLocalization()\n\ntype SecurityItem = {\n scheme: SecuritySchemeObjectSecret | undefined\n name: string\n scopes: string[]\n /** Ordered, non-hidden oauth2/openIdConnect flow keys for this scheme (empty for other types). */\n visibleFlowKeys: (keyof OAuthFlowsObjectSecret)[]\n}\n\n/**\n * Human-readable name of the document type.\n * Used in the missing-type warning so it points at the correct document\n * (e.g. \"AsyncAPI\") instead of always naming OpenAPI.\n */\nconst documentTypeLabel = computed<string>(() =>\n getDocumentTypeLabel(documentType),\n)\n\n/**\n * Resolves security schemes from the OpenAPI document and combines them with their selected scopes.\n * Each item includes the scheme definition, name, and associated scopes.\n */\nconst security = computed<SecurityItem[]>(() =>\n Object.entries(selectedSecuritySchemas).map(([name, scopes = []]) => {\n const scheme = getResolvedRef(securitySchemes[name])\n return {\n scheme,\n name,\n scopes,\n // Compute the visible, ordered flow keys once per scheme so the tabs, the label, and the\n // active-flow tracking all agree on the same set (and we do not filter + sort on every access).\n visibleFlowKeys:\n scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\n ? getVisibleOrderedFlowKeys(scheme.flows)\n : [],\n }\n }),\n)\n\n/** Tracks which OAuth2 flow is currently active when multiple flows are available. */\nconst activeFlow = ref<string>('')\n\n/**\n * Keeps the selected flow in sync with the currently visible flow keys. Validating against the\n * visible set (not every declared flow) means a selection that becomes hidden — e.g. the document\n * is updated to mark the active flow with `x-scalar-ignore` — resets, so the default (first visible)\n * flow activates instead of leaving no tab selected.\n */\nconst selectedFlow = computed<string>(() => {\n const visibleFlowKeys = security.value.flatMap((item) => item.visibleFlowKeys)\n\n return visibleFlowKeys.some((key) => key === activeFlow.value)\n ? activeFlow.value\n : ''\n})\n\nconst setActiveFlow = (flow: string): void => {\n activeFlow.value = flow\n}\n\n/** Determines if multiple auth schemes are configured, which affects the UI layout. */\nconst hasMultipleSchemes = computed<boolean>(() => security.value.length > 1)\n\n/**\n * Generates a human-readable label for the security scheme.\n * Intentionally omits the description here — it is rendered separately as\n * rich text via ScalarMarkdownSummary so markdown formatting is preserved.\n */\nconst generateLabel = (\n name: string,\n scheme: SecuritySchemeObjectSecret,\n): string => {\n const capitalizedName = capitalize(name)\n\n switch (scheme.type) {\n case 'apiKey':\n return `${capitalizedName}: ${scheme.in}`\n\n case 'openIdConnect':\n case 'oauth2': {\n const firstFlow = getVisibleOrderedFlowKeys(scheme.flows)[0]\n const currentFlow = selectedFlow.value || firstFlow\n if (!currentFlow) {\n return capitalizedName\n }\n return `${capitalizedName}: ${currentFlow}`\n }\n\n case 'http':\n return `${capitalizedName}: ${scheme.scheme}`\n\n default:\n return capitalizedName\n }\n}\n\n/**\n * Whether an API key scheme exposes an editable parameter name.\n *\n * OpenAPI `apiKey` and AsyncAPI `httpApiKey` (normalized to `apiKey`) name a query/header/cookie\n * parameter, so the Name input is shown. AsyncAPI `apiKey` places the key in the broker `user` or\n * `password` slot and has no parameter name, so the Name input is hidden and only the value is asked for.\n */\nconst apiKeyHasName = (scheme: { in?: string }): boolean =>\n scheme.in !== 'user' && scheme.in !== 'password'\n\n/**\n * The scheme's type when it is one we do not render inputs for (a type outside both the OpenAPI\n * and AsyncAPI security scheme unions). Read through a helper so the fallback template branch,\n * where the scheme type is narrowed to `never` after the supported cases, can still surface the type.\n */\nconst getUnsupportedSchemeType = (\n scheme: SecurityItem['scheme'],\n): string | undefined => scheme?.type\n\n/**\n * Determines if an OAuth2 flow tab should be active.\n * The first flow is active by default if no flow is explicitly selected.\n */\nconst isFlowActive = (flowKey: string, index: number): boolean =>\n selectedFlow.value === flowKey || (index === 0 && !selectedFlow.value)\n\n/** Computes the container class for static display mode. */\nconst getStaticBorderClass = (): string | false => isStatic && 'border-t'\n\nconst handleHttpSecretsUpdate = (\n payload: Omit<Partial<SecretsHttp>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'http', ...payload },\n name,\n })\n\nconst handleApiKeySecretsUpdate = (\n payload: Omit<Partial<SecretsApiKey>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\nconst handleApiKeySecuritySchemeUpdate = (\n payload: Omit<Partial<ApiKeyObject>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\n/** Handles scope selection updates for OAuth2 */\nconst handleScopesUpdate = (\n name: string,\n event: { scopes?: string[]; scope?: string; selected?: boolean },\n): void => {\n emits('update:selectedScopes', {\n id: Object.keys(selectedSecuritySchemas),\n name,\n ...event,\n })\n}\n\n/** Handles scope-definition upserts (add / rename / description change) */\nconst handleScopeUpsert = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:upsert:scopes'], 'name'>,\n): void => {\n emits('upsert:scope', { ...event, name })\n}\n\n/** Handles scope-definition deletes */\nconst handleScopeDelete = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:delete:scopes'], 'name'>,\n): void => {\n emits('delete:scope', { ...event, name })\n}\n\n/**\n * Computes dynamic classes for OAuth2 flow tabs based on active state.\n */\nconst getFlowTabClasses = (flowKey: string, index: number): string => {\n const baseClasses =\n 'floating-bg text-c-3 relative cursor-pointer border-b border-transparent py-1 text-base font-medium'\n const activeClasses = '!text-c-1 !rounded-none border-b !border-current'\n\n return isFlowActive(flowKey, index)\n ? `${baseClasses} ${activeClasses} ${isStatic ? 'opacity-100' : ''}`\n : baseClasses\n}\n\n/**\n * OAuth2 token-acquisition target (an oauth2 scheme with an interactive grant) sourced from\n * the merged schemes. When the active scheme is HTTP bearer, this powers the inline\n * \"Authorize via OAuth2\" shortcut: the flow's bearer token is written onto the bearer scheme,\n * so the panel never switches to oauth2.\n *\n * The shortcut is purely a convenience, so it is offered for any interactive oauth2 scheme —\n * including one that is also independently selectable in the dropdown (e.g. Scalar Galaxy's\n * `oAuth2`). Whether that oauth2 scheme is *hidden* from the dropdown is a separate decision made\n * in the selector; here we only surface the shortcut.\n */\nconst oauth2Target = computed(() => getOauth2AcquisitionTarget(securitySchemes))\n\n/** Resolved oauth2 scheme object, for embedding its config form behind the gear. */\nconst oauth2Scheme = computed(() =>\n oauth2Target.value\n ? getResolvedRef(securitySchemes[oauth2Target.value.name])\n : undefined,\n)\n\nconst acquisitionLoader = useLoadingState()\nconst { toast } = useToasts()\nconst configModal = useModal()\n/** Bearer scheme that opened the config modal, so its Authorize callback targets it. */\nconst configBearerName = ref<string | undefined>()\n\n/** Runs the OAuth2 flow and writes the resulting bearer token onto the bearer scheme. */\nconst handleAcquisitionAuthorize = async (\n bearerName: string,\n): Promise<void> => {\n const target = oauth2Target.value\n if (!target || acquisitionLoader.isLoading) {\n return\n }\n acquisitionLoader.start()\n const [error] = await runOAuth2Authorize({\n eventBus,\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flows: target.flows,\n flowType: target.flowType,\n scopes: target.scopes,\n server,\n proxyUrl,\n environment,\n options,\n })\n await acquisitionLoader.clear()\n if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToauthorize'),\n 'error',\n )\n }\n}\n\n/** Refreshes the OAuth2 token and rewrites it onto the bearer scheme. */\nconst handleAcquisitionRefresh = async (bearerName: string): Promise<void> => {\n const target = oauth2Target.value\n // Only the authorization-code flow carries a refresh token; implicit can't be refreshed.\n if (\n !target ||\n target.flowType !== 'authorizationCode' ||\n acquisitionLoader.isLoading\n ) {\n return\n }\n acquisitionLoader.start()\n const [error, tokens] = await refreshOauth2Token(\n target.flows,\n target.flowType,\n proxyUrl,\n server,\n getEnvironmentVariables(environment),\n options?.customFetch,\n )\n await acquisitionLoader.clear()\n if (tokens?.accessToken) {\n storeOAuth2Tokens(eventBus, {\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flowType: target.flowType,\n tokens,\n })\n } else if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToRefresh'),\n 'error',\n )\n }\n}\n\nconst openAcquisitionConfig = (bearerName: string): void => {\n configBearerName.value = bearerName\n configModal.show()\n}\n\n/** Closes the config modal and runs Authorize against the bearer scheme that opened it. */\nconst handleConfigAuthorize = (): void => {\n const bearerName = configBearerName.value\n configModal.hide()\n if (bearerName) {\n void handleAcquisitionAuthorize(bearerName)\n }\n}\n</script>\n<template>\n <template\n v-for=\"{ scheme, name, scopes, visibleFlowKeys } in security\"\n :key=\"name\">\n <!--\n Header row for AND'ed schemes: label (bold) and description (rich text) are\n combined.\n -->\n <DataTableRow v-if=\"hasMultipleSchemes && scheme\">\n <DataTableCell\n :aria-label=\"generateLabel(name, scheme)\"\n class=\"max-h-[auto]\">\n <div class=\"bg-b-1 min-w-0 flex-1 px-3 py-1.25\">\n <p class=\"text-c-1 leading-5.5 font-medium\">\n {{ generateLabel(name, scheme) }}\n </p>\n <ScalarMarkdownSummary\n v-if=\"scheme.description\"\n class=\"auth-description text-c-2 w-full\"\n :value=\"scheme.description\" />\n </div>\n </DataTableCell>\n </DataTableRow>\n\n <!-- Description: shown for single auth schemes with descriptions -->\n <DataTableRow v-if=\"scheme?.description && !hasMultipleSchemes\">\n <DataTableCell\n :aria-label=\"scheme.description\"\n class=\"max-h-[auto]\">\n <ScalarMarkdownSummary\n class=\"auth-description bg-b-1 text-c-2 min-w-0 flex-1 px-3 py-1.25\"\n :value=\"scheme.description\" />\n </DataTableCell>\n </DataTableRow>\n\n <!-- HTTP Authentication -->\n <template v-if=\"scheme?.type === 'http'\">\n <!-- Bearer Token -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer'\">\n <RequestAuthDataTableInput\n canReset\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n :placeholder=\"translate('apiClient.requestAuthTab.token')\"\n type=\"password\"\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-token',\n })\n \"\n @update:modelValue=\"\n (v) => handleHttpSecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.bearerToken') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n\n <!-- OAuth2 token-acquisition shortcut (shown when an interactive oauth2 flow exists) -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer' && oauth2Target\">\n <div class=\"flex h-8 items-center gap-2 border-t pl-3 text-base\">\n <span class=\"text-c-1 mr-auto\">{{\n translate('apiClient.requestAuthTab.getAToken')\n }}</span>\n <ScalarButton\n class=\"text-c-1 px-3 py-1\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n type=\"button\"\n variant=\"gradient\"\n @click=\"handleAcquisitionAuthorize(name)\">\n {{\n translate('apiClient.requestAuthTab.authorizeVia', {\n name: oauth2Target.name,\n })\n }}\n </ScalarButton>\n <ScalarButton\n v-if=\"\n scheme['x-scalar-secret-token'] &&\n oauth2Target.flowType === 'authorizationCode'\n \"\n class=\"px-3 py-1\"\n :disabled=\"acquisitionLoader.isLoading\"\n size=\"sm\"\n type=\"button\"\n variant=\"outlined\"\n @click=\"handleAcquisitionRefresh(name)\">\n {{ translate('apiClient.requestAuthTab.refresh') }}\n </ScalarButton>\n <!-- Sized and inset like the password toggle in the row above so the two icons line up -->\n <ScalarIconButton\n class=\"mr-1.25 h-6 w-6 p-1.25\"\n :icon=\"ScalarIconGear\"\n :label=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \"\n @click=\"openAcquisitionConfig(name)\" />\n </div>\n </DataTableRow>\n\n <!-- HTTP Basic Authentication -->\n <template v-else-if=\"scheme?.scheme === 'basic'\">\n <DataTableRow>\n <RequestAuthDataTableInput\n canReset\n class=\"text-c-2\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-username']\"\n placeholder=\"janedoe\"\n required\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-username',\n })\n \"\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-username': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.username') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n canReset\n :environment\n :modelValue=\"scheme['x-scalar-secret-password']\"\n placeholder=\"********\"\n type=\"password\"\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-password',\n })\n \"\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-password': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.password') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n </template>\n\n <!-- API Key Authentication -->\n <template v-else-if=\"scheme?.type === 'apiKey'\">\n <DataTableRow v-if=\"apiKeyHasName(scheme)\">\n <RequestAuthDataTableInput\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme.name ?? ''\"\n placeholder=\"api-key\"\n @update:modelValue=\"\n (v) => handleApiKeySecuritySchemeUpdate({ name: v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.name') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n canReset\n :containerClass=\"\n apiKeyHasName(scheme) ? undefined : getStaticBorderClass()\n \"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n placeholder=\"QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT\"\n type=\"password\"\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-token',\n })\n \"\n @update:modelValue=\"\n (v) =>\n handleApiKeySecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.value') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n\n <!-- OAuth 2.0 / OpenID Connect Authentication -->\n <template\n v-else-if=\"scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\">\n <OAuth2Metadata\n v-if=\"\n scheme.type === 'oauth2' && (!isStatic || scheme.oauth2MetadataUrl)\n \"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :name\n :proxyUrl\n :scheme />\n\n <!-- OpenID Connect -->\n <OpenIDConnect\n v-if=\"scheme?.type === 'openIdConnect' && !visibleFlowKeys.length\"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :getStaticBorderClass\n :name\n :proxyUrl\n :scheme />\n\n <!-- Flow selector tabs: shown when multiple visible flows are available -->\n <DataTableRow v-if=\"visibleFlowKeys.length > 1\">\n <div class=\"flex min-h-8 border-t text-base\">\n <div class=\"flex h-8 max-w-full gap-2.5 overflow-x-auto px-3\">\n <button\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\"\n :class=\"getFlowTabClasses(key, ind)\"\n type=\"button\"\n @click=\"setActiveFlow(key)\">\n <span class=\"relative z-10\">{{ key }}</span>\n </button>\n </div>\n </div>\n </DataTableRow>\n\n <!-- OAuth2 flow configuration -->\n <template\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\">\n <OAuth2\n v-if=\"scheme.flows && isFlowActive(key, ind)\"\n :environment\n :eventBus\n :flows=\"scheme.flows\"\n :name\n :options\n :proxyUrl\n :scheme\n :selectedScopes=\"scopes\"\n :server\n :type=\"key\"\n @delete:scope=\"(event) => handleScopeDelete(name, event)\"\n @update:selectedScopes=\"(event) => handleScopesUpdate(name, event)\"\n @upsert:scope=\"(event) => handleScopeUpsert(name, event)\" />\n </template>\n </template>\n\n <!-- Browser WebSocket connections cannot apply these broker credentials. -->\n <div\n v-else-if=\"\n scheme?.type === 'userPassword' ||\n scheme?.type === 'plain' ||\n scheme?.type === 'scramSha256' ||\n scheme?.type === 'scramSha512' ||\n scheme?.type === 'X509' ||\n scheme?.type === 'symmetricEncryption' ||\n scheme?.type === 'asymmetricEncryption' ||\n scheme?.type === 'gssapi'\n \"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.unsupportedCredentials') }}\n </div>\n\n <!-- Mutual TLS credentials are chosen during the browser-managed TLS handshake. -->\n <div\n v-else-if=\"scheme?.type === 'mutualTLS'\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.mutualTlsHint') }}\n </div>\n\n <!-- Scheme has a type we do not render inputs for -->\n <div\n v-else-if=\"getUnsupportedSchemeType(scheme)\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.unsupportedType', {\n type: getUnsupportedSchemeType(scheme) ?? '',\n })\n }}\n </div>\n\n <!-- Scheme is missing type -->\n <div\n v-else\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.missingType', {\n type: documentTypeLabel,\n })\n }}\n </div>\n </template>\n\n <!-- OAuth2 configuration modal (opened from the bearer scheme's gear) -->\n <ScalarModal\n v-if=\"oauth2Target && oauth2Scheme\"\n size=\"sm\"\n :state=\"configModal\"\n :title=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \">\n <DataTable\n :columns=\"['']\"\n presentational>\n <OAuth2\n :environment\n :eventBus\n :flows=\"oauth2Target.flows\"\n hideActions\n :name=\"oauth2Target.name\"\n :options\n :proxyUrl\n :scheme=\"oauth2Scheme\"\n :selectedScopes=\"oauth2Target.scopes\"\n :server\n :type=\"oauth2Target.flowType\"\n @delete:scope=\"(event) => handleScopeDelete(oauth2Target!.name, event)\"\n @update:selectedScopes=\"\n (event) => handleScopesUpdate(oauth2Target!.name, event)\n \"\n @upsert:scope=\"\n (event) => handleScopeUpsert(oauth2Target!.name, event)\n \" />\n </DataTable>\n <div class=\"flex h-8 items-center justify-end gap-2 border-t\">\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"configModal.hide()\">\n {{ translate('apiClient.requestAuthTab.cancel') }}\n </ScalarButton>\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n @click=\"handleConfigAuthorize\">\n {{ translate('apiClient.requestAuthTab.authorize') }}\n </ScalarButton>\n </div>\n </ScalarModal>\n</template>\n"],"mappings":""}
@@ -24,8 +24,8 @@ import { getDocumentTypeLabel } from "@scalar/workspace-store/schemas/type-guard
24
24
  //#region src/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue?vue&type=script&setup=true&lang.ts
25
25
  var _hoisted_1 = { class: "bg-b-1 min-w-0 flex-1 px-3 py-1.25" };
26
26
  var _hoisted_2 = { class: "text-c-1 leading-5.5 font-medium" };
27
- var _hoisted_3 = { class: "flex h-8 items-center gap-2 border-t px-3" };
28
- var _hoisted_4 = { class: "text-c-3 mr-auto text-xs" };
27
+ var _hoisted_3 = { class: "flex h-8 items-center gap-2 border-t pl-3 text-base" };
28
+ var _hoisted_4 = { class: "text-c-1 mr-auto" };
29
29
  var _hoisted_5 = { class: "flex min-h-8 border-t text-base" };
30
30
  var _hoisted_6 = { class: "flex h-8 max-w-full gap-2.5 overflow-x-auto px-3" };
31
31
  var _hoisted_7 = ["onClick"];
@@ -290,11 +290,16 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
290
290
  }, 1024)) : createCommentVNode("", true),
291
291
  scheme?.type === "http" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [scheme.scheme === "bearer" ? (openBlock(), createBlock(unref(DataTableRow_default), { key: 0 }, {
292
292
  default: withCtx(() => [createVNode(RequestAuthDataTableInput_default, {
293
+ canReset: "",
293
294
  containerClass: getStaticBorderClass(),
294
295
  environment: __props.environment,
295
296
  modelValue: scheme["x-scalar-secret-token"],
296
297
  placeholder: unref(translate)("apiClient.requestAuthTab.token"),
297
298
  type: "password",
299
+ onReset: ($event) => __props.eventBus.emit("auth:reset:security-scheme-secret", {
300
+ name,
301
+ field: "x-scalar-secret-token"
302
+ }),
298
303
  "onUpdate:modelValue": (v) => handleHttpSecretsUpdate({ "x-scalar-secret-token": v }, name)
299
304
  }, {
300
305
  default: withCtx(() => [createTextVNode(toDisplayString(unref(translate)("apiClient.requestAuthTab.bearerToken")), 1)]),
@@ -304,6 +309,7 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
304
309
  "environment",
305
310
  "modelValue",
306
311
  "placeholder",
312
+ "onReset",
307
313
  "onUpdate:modelValue"
308
314
  ])]),
309
315
  _: 2
@@ -311,11 +317,11 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
311
317
  default: withCtx(() => [createElementVNode("div", _hoisted_3, [
312
318
  createElementVNode("span", _hoisted_4, toDisplayString(unref(translate)("apiClient.requestAuthTab.getAToken")), 1),
313
319
  createVNode(unref(ScalarButton), {
314
- class: "p-0 px-2 py-0.5",
320
+ class: "text-c-1 px-3 py-1",
315
321
  loader: unref(acquisitionLoader),
316
322
  size: "sm",
317
323
  type: "button",
318
- variant: "outlined",
324
+ variant: "gradient",
319
325
  onClick: ($event) => handleAcquisitionAuthorize(name)
320
326
  }, {
321
327
  default: withCtx(() => [createTextVNode(toDisplayString(unref(translate)("apiClient.requestAuthTab.authorizeVia", { name: oauth2Target.value.name })), 1)]),
@@ -323,7 +329,7 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
323
329
  }, 1032, ["loader", "onClick"]),
324
330
  scheme["x-scalar-secret-token"] && oauth2Target.value.flowType === "authorizationCode" ? (openBlock(), createBlock(unref(ScalarButton), {
325
331
  key: 0,
326
- class: "p-0 px-2 py-0.5",
332
+ class: "px-3 py-1",
327
333
  disabled: unref(acquisitionLoader).isLoading,
328
334
  size: "sm",
329
335
  type: "button",
@@ -334,9 +340,9 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
334
340
  _: 1
335
341
  }, 8, ["disabled", "onClick"])) : createCommentVNode("", true),
336
342
  createVNode(unref(ScalarIconButton), {
343
+ class: "mr-1.25 h-6 w-6 p-1.25",
337
344
  icon: unref(ScalarIconGear),
338
345
  label: unref(translate)("apiClient.requestAuthTab.configure", { name: oauth2Target.value.name }),
339
- size: "xs",
340
346
  onClick: ($event) => openAcquisitionConfig(name)
341
347
  }, null, 8, [
342
348
  "icon",
@@ -347,11 +353,16 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
347
353
  _: 2
348
354
  }, 1024)) : scheme?.scheme === "basic" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [createVNode(unref(DataTableRow_default), null, {
349
355
  default: withCtx(() => [createVNode(RequestAuthDataTableInput_default, {
356
+ canReset: "",
350
357
  class: "text-c-2",
351
358
  environment: __props.environment,
352
359
  modelValue: scheme["x-scalar-secret-username"],
353
360
  placeholder: "janedoe",
354
361
  required: "",
362
+ onReset: ($event) => __props.eventBus.emit("auth:reset:security-scheme-secret", {
363
+ name,
364
+ field: "x-scalar-secret-username"
365
+ }),
355
366
  "onUpdate:modelValue": (v) => handleHttpSecretsUpdate({ "x-scalar-secret-username": v }, name)
356
367
  }, {
357
368
  default: withCtx(() => [createTextVNode(toDisplayString(unref(translate)("apiClient.requestAuthTab.username")), 1)]),
@@ -359,15 +370,21 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
359
370
  }, 8, [
360
371
  "environment",
361
372
  "modelValue",
373
+ "onReset",
362
374
  "onUpdate:modelValue"
363
375
  ])]),
364
376
  _: 2
365
377
  }, 1024), createVNode(unref(DataTableRow_default), null, {
366
378
  default: withCtx(() => [createVNode(RequestAuthDataTableInput_default, {
379
+ canReset: "",
367
380
  environment: __props.environment,
368
381
  modelValue: scheme["x-scalar-secret-password"],
369
382
  placeholder: "********",
370
383
  type: "password",
384
+ onReset: ($event) => __props.eventBus.emit("auth:reset:security-scheme-secret", {
385
+ name,
386
+ field: "x-scalar-secret-password"
387
+ }),
371
388
  "onUpdate:modelValue": (v) => handleHttpSecretsUpdate({ "x-scalar-secret-password": v }, name)
372
389
  }, {
373
390
  default: withCtx(() => [createTextVNode(toDisplayString(unref(translate)("apiClient.requestAuthTab.password")), 1)]),
@@ -375,6 +392,7 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
375
392
  }, 8, [
376
393
  "environment",
377
394
  "modelValue",
395
+ "onReset",
378
396
  "onUpdate:modelValue"
379
397
  ])]),
380
398
  _: 2
@@ -397,11 +415,16 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
397
415
  _: 2
398
416
  }, 1024)) : createCommentVNode("", true), createVNode(unref(DataTableRow_default), null, {
399
417
  default: withCtx(() => [createVNode(RequestAuthDataTableInput_default, {
418
+ canReset: "",
400
419
  containerClass: apiKeyHasName(scheme) ? void 0 : getStaticBorderClass(),
401
420
  environment: __props.environment,
402
421
  modelValue: scheme["x-scalar-secret-token"],
403
422
  placeholder: "QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT",
404
423
  type: "password",
424
+ onReset: ($event) => __props.eventBus.emit("auth:reset:security-scheme-secret", {
425
+ name,
426
+ field: "x-scalar-secret-token"
427
+ }),
405
428
  "onUpdate:modelValue": (v) => handleApiKeySecretsUpdate({ "x-scalar-secret-token": v }, name)
406
429
  }, {
407
430
  default: withCtx(() => [createTextVNode(toDisplayString(unref(translate)("apiClient.requestAuthTab.value")), 1)]),
@@ -410,6 +433,7 @@ var RequestAuthTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
410
433
  "containerClass",
411
434
  "environment",
412
435
  "modelValue",
436
+ "onReset",
413
437
  "onUpdate:modelValue"
414
438
  ])]),
415
439
  _: 2
@@ -1 +1 @@
1
- {"version":3,"file":"RequestAuthTab.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { useLoadingState } from '@scalar/components/loading'\nimport { ScalarMarkdownSummary } from '@scalar/components/markdown'\nimport { ScalarModal, useModal } from '@scalar/components/modal'\nimport { ScalarIconGear } from '@scalar/icons'\nimport { useToasts } from '@scalar/use-toasts'\nimport type {\n SecretsApiKey,\n SecretsHttp,\n} from '@scalar/workspace-store/entities/auth'\nimport type {\n ApiReferenceEvents,\n WorkspaceEventBus,\n} from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n getEnvironmentVariables,\n type MergedSecuritySchemes,\n type OAuthFlowsObjectSecret,\n type SecuritySchemeObjectSecret,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { getDocumentTypeLabel } from '@scalar/workspace-store/schemas/type-guards'\nimport type {\n ApiKeyObject,\n SecurityRequirementObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { capitalize, computed, ref } from 'vue'\n\nimport { refreshOauth2Token } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth'\nimport { getVisibleOrderedFlowKeys } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth-flows'\nimport {\n runOAuth2Authorize,\n storeOAuth2Tokens,\n} from '@/v2/blocks/scalar-auth-selector-block/helpers/run-oauth2-authorize'\nimport { getOauth2AcquisitionTarget } from '@/v2/blocks/scalar-auth-selector-block/helpers/security-scheme'\nimport {\n DataTable,\n DataTableCell,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport OAuth2, { type OAuth2Options } from './OAuth2.vue'\nimport OAuth2Metadata from './OAuth2Metadata.vue'\nimport OpenIDConnect from './OpenIDConnect.vue'\nimport RequestAuthDataTableInput from './RequestAuthDataTableInput.vue'\n\nconst {\n environment,\n isStatic,\n proxyUrl,\n selectedSecuritySchemas,\n securitySchemes,\n server,\n eventBus,\n options,\n documentType = 'openapi',\n} = defineProps<{\n /** Current environment configuration */\n environment: XScalarEnvironment\n /** Controls the display of certain borders which are used when we are non-collapsible */\n isStatic: boolean\n /** Proxy URL */\n proxyUrl: string\n /** Selected security schemes*/\n selectedSecuritySchemas: SecurityRequirementObject\n /** Merged security schemes from the document and the config together with the auth store secrets */\n securitySchemes: MergedSecuritySchemes\n /** Current server configuration */\n server: ServerObject | null\n /** Event bus for authentication updates */\n eventBus: WorkspaceEventBus\n /** Any config options required for the OAuth2 flow */\n options?: OAuth2Options\n /** Type of the document the schemes belong to, used to label the missing-type warning */\n documentType?: 'openapi' | 'asyncapi'\n}>()\n\nconst emits = defineEmits<{\n (\n e: 'update:selectedScopes',\n payload: Omit<ApiReferenceEvents['auth:update:selected-scopes'], 'meta'>,\n ): void\n (e: 'upsert:scope', payload: ApiReferenceEvents['auth:upsert:scopes']): void\n (e: 'delete:scope', payload: ApiReferenceEvents['auth:delete:scopes']): void\n}>()\n\nconst { translate } = useLocalization()\n\ntype SecurityItem = {\n scheme: SecuritySchemeObjectSecret | undefined\n name: string\n scopes: string[]\n /** Ordered, non-hidden oauth2/openIdConnect flow keys for this scheme (empty for other types). */\n visibleFlowKeys: (keyof OAuthFlowsObjectSecret)[]\n}\n\n/**\n * Human-readable name of the document type.\n * Used in the missing-type warning so it points at the correct document\n * (e.g. \"AsyncAPI\") instead of always naming OpenAPI.\n */\nconst documentTypeLabel = computed<string>(() =>\n getDocumentTypeLabel(documentType),\n)\n\n/**\n * Resolves security schemes from the OpenAPI document and combines them with their selected scopes.\n * Each item includes the scheme definition, name, and associated scopes.\n */\nconst security = computed<SecurityItem[]>(() =>\n Object.entries(selectedSecuritySchemas).map(([name, scopes = []]) => {\n const scheme = getResolvedRef(securitySchemes[name])\n return {\n scheme,\n name,\n scopes,\n // Compute the visible, ordered flow keys once per scheme so the tabs, the label, and the\n // active-flow tracking all agree on the same set (and we do not filter + sort on every access).\n visibleFlowKeys:\n scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\n ? getVisibleOrderedFlowKeys(scheme.flows)\n : [],\n }\n }),\n)\n\n/** Tracks which OAuth2 flow is currently active when multiple flows are available. */\nconst activeFlow = ref<string>('')\n\n/**\n * Keeps the selected flow in sync with the currently visible flow keys. Validating against the\n * visible set (not every declared flow) means a selection that becomes hidden — e.g. the document\n * is updated to mark the active flow with `x-scalar-ignore` — resets, so the default (first visible)\n * flow activates instead of leaving no tab selected.\n */\nconst selectedFlow = computed<string>(() => {\n const visibleFlowKeys = security.value.flatMap((item) => item.visibleFlowKeys)\n\n return visibleFlowKeys.some((key) => key === activeFlow.value)\n ? activeFlow.value\n : ''\n})\n\nconst setActiveFlow = (flow: string): void => {\n activeFlow.value = flow\n}\n\n/** Determines if multiple auth schemes are configured, which affects the UI layout. */\nconst hasMultipleSchemes = computed<boolean>(() => security.value.length > 1)\n\n/**\n * Generates a human-readable label for the security scheme.\n * Intentionally omits the description here — it is rendered separately as\n * rich text via ScalarMarkdownSummary so markdown formatting is preserved.\n */\nconst generateLabel = (\n name: string,\n scheme: SecuritySchemeObjectSecret,\n): string => {\n const capitalizedName = capitalize(name)\n\n switch (scheme.type) {\n case 'apiKey':\n return `${capitalizedName}: ${scheme.in}`\n\n case 'openIdConnect':\n case 'oauth2': {\n const firstFlow = getVisibleOrderedFlowKeys(scheme.flows)[0]\n const currentFlow = selectedFlow.value || firstFlow\n if (!currentFlow) {\n return capitalizedName\n }\n return `${capitalizedName}: ${currentFlow}`\n }\n\n case 'http':\n return `${capitalizedName}: ${scheme.scheme}`\n\n default:\n return capitalizedName\n }\n}\n\n/**\n * Whether an API key scheme exposes an editable parameter name.\n *\n * OpenAPI `apiKey` and AsyncAPI `httpApiKey` (normalized to `apiKey`) name a query/header/cookie\n * parameter, so the Name input is shown. AsyncAPI `apiKey` places the key in the broker `user` or\n * `password` slot and has no parameter name, so the Name input is hidden and only the value is asked for.\n */\nconst apiKeyHasName = (scheme: { in?: string }): boolean =>\n scheme.in !== 'user' && scheme.in !== 'password'\n\n/**\n * The scheme's type when it is one we do not render inputs for (a type outside both the OpenAPI\n * and AsyncAPI security scheme unions). Read through a helper so the fallback template branch,\n * where the scheme type is narrowed to `never` after the supported cases, can still surface the type.\n */\nconst getUnsupportedSchemeType = (\n scheme: SecurityItem['scheme'],\n): string | undefined => scheme?.type\n\n/**\n * Determines if an OAuth2 flow tab should be active.\n * The first flow is active by default if no flow is explicitly selected.\n */\nconst isFlowActive = (flowKey: string, index: number): boolean =>\n selectedFlow.value === flowKey || (index === 0 && !selectedFlow.value)\n\n/** Computes the container class for static display mode. */\nconst getStaticBorderClass = (): string | false => isStatic && 'border-t'\n\nconst handleHttpSecretsUpdate = (\n payload: Omit<Partial<SecretsHttp>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'http', ...payload },\n name,\n })\n\nconst handleApiKeySecretsUpdate = (\n payload: Omit<Partial<SecretsApiKey>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\nconst handleApiKeySecuritySchemeUpdate = (\n payload: Omit<Partial<ApiKeyObject>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\n/** Handles scope selection updates for OAuth2 */\nconst handleScopesUpdate = (\n name: string,\n event: { scopes?: string[]; scope?: string; selected?: boolean },\n): void => {\n emits('update:selectedScopes', {\n id: Object.keys(selectedSecuritySchemas),\n name,\n ...event,\n })\n}\n\n/** Handles scope-definition upserts (add / rename / description change) */\nconst handleScopeUpsert = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:upsert:scopes'], 'name'>,\n): void => {\n emits('upsert:scope', { ...event, name })\n}\n\n/** Handles scope-definition deletes */\nconst handleScopeDelete = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:delete:scopes'], 'name'>,\n): void => {\n emits('delete:scope', { ...event, name })\n}\n\n/**\n * Computes dynamic classes for OAuth2 flow tabs based on active state.\n */\nconst getFlowTabClasses = (flowKey: string, index: number): string => {\n const baseClasses =\n 'floating-bg text-c-3 relative cursor-pointer border-b border-transparent py-1 text-base font-medium'\n const activeClasses = '!text-c-1 !rounded-none border-b !border-current'\n\n return isFlowActive(flowKey, index)\n ? `${baseClasses} ${activeClasses} ${isStatic ? 'opacity-100' : ''}`\n : baseClasses\n}\n\n/**\n * OAuth2 token-acquisition target (an oauth2 scheme with an interactive grant) sourced from\n * the merged schemes. When the active scheme is HTTP bearer, this powers the inline\n * \"Authorize via OAuth2\" shortcut: the flow's bearer token is written onto the bearer scheme,\n * so the panel never switches to oauth2.\n *\n * The shortcut is purely a convenience, so it is offered for any interactive oauth2 scheme —\n * including one that is also independently selectable in the dropdown (e.g. Scalar Galaxy's\n * `oAuth2`). Whether that oauth2 scheme is *hidden* from the dropdown is a separate decision made\n * in the selector; here we only surface the shortcut.\n */\nconst oauth2Target = computed(() => getOauth2AcquisitionTarget(securitySchemes))\n\n/** Resolved oauth2 scheme object, for embedding its config form behind the gear. */\nconst oauth2Scheme = computed(() =>\n oauth2Target.value\n ? getResolvedRef(securitySchemes[oauth2Target.value.name])\n : undefined,\n)\n\nconst acquisitionLoader = useLoadingState()\nconst { toast } = useToasts()\nconst configModal = useModal()\n/** Bearer scheme that opened the config modal, so its Authorize callback targets it. */\nconst configBearerName = ref<string | undefined>()\n\n/** Runs the OAuth2 flow and writes the resulting bearer token onto the bearer scheme. */\nconst handleAcquisitionAuthorize = async (\n bearerName: string,\n): Promise<void> => {\n const target = oauth2Target.value\n if (!target || acquisitionLoader.isLoading) {\n return\n }\n acquisitionLoader.start()\n const [error] = await runOAuth2Authorize({\n eventBus,\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flows: target.flows,\n flowType: target.flowType,\n scopes: target.scopes,\n server,\n proxyUrl,\n environment,\n options,\n })\n await acquisitionLoader.clear()\n if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToauthorize'),\n 'error',\n )\n }\n}\n\n/** Refreshes the OAuth2 token and rewrites it onto the bearer scheme. */\nconst handleAcquisitionRefresh = async (bearerName: string): Promise<void> => {\n const target = oauth2Target.value\n // Only the authorization-code flow carries a refresh token; implicit can't be refreshed.\n if (\n !target ||\n target.flowType !== 'authorizationCode' ||\n acquisitionLoader.isLoading\n ) {\n return\n }\n acquisitionLoader.start()\n const [error, tokens] = await refreshOauth2Token(\n target.flows,\n target.flowType,\n proxyUrl,\n server,\n getEnvironmentVariables(environment),\n options?.customFetch,\n )\n await acquisitionLoader.clear()\n if (tokens?.accessToken) {\n storeOAuth2Tokens(eventBus, {\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flowType: target.flowType,\n tokens,\n })\n } else if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToRefresh'),\n 'error',\n )\n }\n}\n\nconst openAcquisitionConfig = (bearerName: string): void => {\n configBearerName.value = bearerName\n configModal.show()\n}\n\n/** Closes the config modal and runs Authorize against the bearer scheme that opened it. */\nconst handleConfigAuthorize = (): void => {\n const bearerName = configBearerName.value\n configModal.hide()\n if (bearerName) {\n void handleAcquisitionAuthorize(bearerName)\n }\n}\n</script>\n<template>\n <template\n v-for=\"{ scheme, name, scopes, visibleFlowKeys } in security\"\n :key=\"name\">\n <!--\n Header row for AND'ed schemes: label (bold) and description (rich text) are\n combined.\n -->\n <DataTableRow v-if=\"hasMultipleSchemes && scheme\">\n <DataTableCell\n :aria-label=\"generateLabel(name, scheme)\"\n class=\"max-h-[auto]\">\n <div class=\"bg-b-1 min-w-0 flex-1 px-3 py-1.25\">\n <p class=\"text-c-1 leading-5.5 font-medium\">\n {{ generateLabel(name, scheme) }}\n </p>\n <ScalarMarkdownSummary\n v-if=\"scheme.description\"\n class=\"auth-description text-c-2 w-full\"\n :value=\"scheme.description\" />\n </div>\n </DataTableCell>\n </DataTableRow>\n\n <!-- Description: shown for single auth schemes with descriptions -->\n <DataTableRow v-if=\"scheme?.description && !hasMultipleSchemes\">\n <DataTableCell\n :aria-label=\"scheme.description\"\n class=\"max-h-[auto]\">\n <ScalarMarkdownSummary\n class=\"auth-description bg-b-1 text-c-2 min-w-0 flex-1 px-3 py-1.25\"\n :value=\"scheme.description\" />\n </DataTableCell>\n </DataTableRow>\n\n <!-- HTTP Authentication -->\n <template v-if=\"scheme?.type === 'http'\">\n <!-- Bearer Token -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer'\">\n <RequestAuthDataTableInput\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n :placeholder=\"translate('apiClient.requestAuthTab.token')\"\n type=\"password\"\n @update:modelValue=\"\n (v) => handleHttpSecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.bearerToken') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n\n <!-- OAuth2 token-acquisition shortcut (shown when an interactive oauth2 flow exists) -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer' && oauth2Target\">\n <div class=\"flex h-8 items-center gap-2 border-t px-3\">\n <span class=\"text-c-3 mr-auto text-xs\">{{\n translate('apiClient.requestAuthTab.getAToken')\n }}</span>\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n type=\"button\"\n variant=\"outlined\"\n @click=\"handleAcquisitionAuthorize(name)\">\n {{\n translate('apiClient.requestAuthTab.authorizeVia', {\n name: oauth2Target.name,\n })\n }}\n </ScalarButton>\n <ScalarButton\n v-if=\"\n scheme['x-scalar-secret-token'] &&\n oauth2Target.flowType === 'authorizationCode'\n \"\n class=\"p-0 px-2 py-0.5\"\n :disabled=\"acquisitionLoader.isLoading\"\n size=\"sm\"\n type=\"button\"\n variant=\"outlined\"\n @click=\"handleAcquisitionRefresh(name)\">\n {{ translate('apiClient.requestAuthTab.refresh') }}\n </ScalarButton>\n <ScalarIconButton\n :icon=\"ScalarIconGear\"\n :label=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \"\n size=\"xs\"\n @click=\"openAcquisitionConfig(name)\" />\n </div>\n </DataTableRow>\n\n <!-- HTTP Basic Authentication -->\n <template v-else-if=\"scheme?.scheme === 'basic'\">\n <DataTableRow>\n <RequestAuthDataTableInput\n class=\"text-c-2\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-username']\"\n placeholder=\"janedoe\"\n required\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-username': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.username') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n :environment\n :modelValue=\"scheme['x-scalar-secret-password']\"\n placeholder=\"********\"\n type=\"password\"\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-password': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.password') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n </template>\n\n <!-- API Key Authentication -->\n <template v-else-if=\"scheme?.type === 'apiKey'\">\n <DataTableRow v-if=\"apiKeyHasName(scheme)\">\n <RequestAuthDataTableInput\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme.name ?? ''\"\n placeholder=\"api-key\"\n @update:modelValue=\"\n (v) => handleApiKeySecuritySchemeUpdate({ name: v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.name') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n :containerClass=\"\n apiKeyHasName(scheme) ? undefined : getStaticBorderClass()\n \"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n placeholder=\"QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT\"\n type=\"password\"\n @update:modelValue=\"\n (v) =>\n handleApiKeySecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.value') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n\n <!-- OAuth 2.0 / OpenID Connect Authentication -->\n <template\n v-else-if=\"scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\">\n <OAuth2Metadata\n v-if=\"\n scheme.type === 'oauth2' && (!isStatic || scheme.oauth2MetadataUrl)\n \"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :name\n :proxyUrl\n :scheme />\n\n <!-- OpenID Connect -->\n <OpenIDConnect\n v-if=\"scheme?.type === 'openIdConnect' && !visibleFlowKeys.length\"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :getStaticBorderClass\n :name\n :proxyUrl\n :scheme />\n\n <!-- Flow selector tabs: shown when multiple visible flows are available -->\n <DataTableRow v-if=\"visibleFlowKeys.length > 1\">\n <div class=\"flex min-h-8 border-t text-base\">\n <div class=\"flex h-8 max-w-full gap-2.5 overflow-x-auto px-3\">\n <button\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\"\n :class=\"getFlowTabClasses(key, ind)\"\n type=\"button\"\n @click=\"setActiveFlow(key)\">\n <span class=\"relative z-10\">{{ key }}</span>\n </button>\n </div>\n </div>\n </DataTableRow>\n\n <!-- OAuth2 flow configuration -->\n <template\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\">\n <OAuth2\n v-if=\"scheme.flows && isFlowActive(key, ind)\"\n :environment\n :eventBus\n :flows=\"scheme.flows\"\n :name\n :options\n :proxyUrl\n :scheme\n :selectedScopes=\"scopes\"\n :server\n :type=\"key\"\n @delete:scope=\"(event) => handleScopeDelete(name, event)\"\n @update:selectedScopes=\"(event) => handleScopesUpdate(name, event)\"\n @upsert:scope=\"(event) => handleScopeUpsert(name, event)\" />\n </template>\n </template>\n\n <!-- Browser WebSocket connections cannot apply these broker credentials. -->\n <div\n v-else-if=\"\n scheme?.type === 'userPassword' ||\n scheme?.type === 'plain' ||\n scheme?.type === 'scramSha256' ||\n scheme?.type === 'scramSha512' ||\n scheme?.type === 'X509' ||\n scheme?.type === 'symmetricEncryption' ||\n scheme?.type === 'asymmetricEncryption' ||\n scheme?.type === 'gssapi'\n \"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.unsupportedCredentials') }}\n </div>\n\n <!-- Mutual TLS credentials are chosen during the browser-managed TLS handshake. -->\n <div\n v-else-if=\"scheme?.type === 'mutualTLS'\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.mutualTlsHint') }}\n </div>\n\n <!-- Scheme has a type we do not render inputs for -->\n <div\n v-else-if=\"getUnsupportedSchemeType(scheme)\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.unsupportedType', {\n type: getUnsupportedSchemeType(scheme) ?? '',\n })\n }}\n </div>\n\n <!-- Scheme is missing type -->\n <div\n v-else\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.missingType', {\n type: documentTypeLabel,\n })\n }}\n </div>\n </template>\n\n <!-- OAuth2 configuration modal (opened from the bearer scheme's gear) -->\n <ScalarModal\n v-if=\"oauth2Target && oauth2Scheme\"\n size=\"sm\"\n :state=\"configModal\"\n :title=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \">\n <DataTable\n :columns=\"['']\"\n presentational>\n <OAuth2\n :environment\n :eventBus\n :flows=\"oauth2Target.flows\"\n hideActions\n :name=\"oauth2Target.name\"\n :options\n :proxyUrl\n :scheme=\"oauth2Scheme\"\n :selectedScopes=\"oauth2Target.scopes\"\n :server\n :type=\"oauth2Target.flowType\"\n @delete:scope=\"(event) => handleScopeDelete(oauth2Target!.name, event)\"\n @update:selectedScopes=\"\n (event) => handleScopesUpdate(oauth2Target!.name, event)\n \"\n @upsert:scope=\"\n (event) => handleScopeUpsert(oauth2Target!.name, event)\n \" />\n </DataTable>\n <div class=\"flex h-8 items-center justify-end gap-2 border-t\">\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"configModal.hide()\">\n {{ translate('apiClient.requestAuthTab.cancel') }}\n </ScalarButton>\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n @click=\"handleConfigAuthorize\">\n {{ translate('apiClient.requestAuthTab.authorize') }}\n </ScalarButton>\n </div>\n </ScalarModal>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkFA,MAAM,QAAQ;EASd,MAAM,EAAE,cAAc,gBAAg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I;;4BAC0B,CAAA,gBAAA,gBAA/C,MAAA,SAAA,CAAS,CAAA,iCAAA,CAAA,GAAA,CAAA,CAAA,CAAA;;QAEd,YAMe,MAAA,YAAA,GAAA;KALb,OAAM;KACL,QAAQ,MAAA,iBAAA;KACT,MAAK;KACJ,SAAO;;4BAC6C,CAAA,gBAAA,gBAAlD,MAAA,SAAA,CAAS,CAAA,oCAAA,CAAA,GAAA,CAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"RequestAuthTab.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { useLoadingState } from '@scalar/components/loading'\nimport { ScalarMarkdownSummary } from '@scalar/components/markdown'\nimport { ScalarModal, useModal } from '@scalar/components/modal'\nimport { ScalarIconGear } from '@scalar/icons'\nimport { useToasts } from '@scalar/use-toasts'\nimport type {\n SecretsApiKey,\n SecretsHttp,\n} from '@scalar/workspace-store/entities/auth'\nimport type {\n ApiReferenceEvents,\n WorkspaceEventBus,\n} from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n getEnvironmentVariables,\n type MergedSecuritySchemes,\n type OAuthFlowsObjectSecret,\n type SecuritySchemeObjectSecret,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport { getDocumentTypeLabel } from '@scalar/workspace-store/schemas/type-guards'\nimport type {\n ApiKeyObject,\n SecurityRequirementObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { capitalize, computed, ref } from 'vue'\n\nimport { refreshOauth2Token } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth'\nimport { getVisibleOrderedFlowKeys } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth-flows'\nimport {\n runOAuth2Authorize,\n storeOAuth2Tokens,\n} from '@/v2/blocks/scalar-auth-selector-block/helpers/run-oauth2-authorize'\nimport { getOauth2AcquisitionTarget } from '@/v2/blocks/scalar-auth-selector-block/helpers/security-scheme'\nimport {\n DataTable,\n DataTableCell,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport OAuth2, { type OAuth2Options } from './OAuth2.vue'\nimport OAuth2Metadata from './OAuth2Metadata.vue'\nimport OpenIDConnect from './OpenIDConnect.vue'\nimport RequestAuthDataTableInput from './RequestAuthDataTableInput.vue'\n\nconst {\n environment,\n isStatic,\n proxyUrl,\n selectedSecuritySchemas,\n securitySchemes,\n server,\n eventBus,\n options,\n documentType = 'openapi',\n} = defineProps<{\n /** Current environment configuration */\n environment: XScalarEnvironment\n /** Controls the display of certain borders which are used when we are non-collapsible */\n isStatic: boolean\n /** Proxy URL */\n proxyUrl: string\n /** Selected security schemes*/\n selectedSecuritySchemas: SecurityRequirementObject\n /** Merged security schemes from the document and the config together with the auth store secrets */\n securitySchemes: MergedSecuritySchemes\n /** Current server configuration */\n server: ServerObject | null\n /** Event bus for authentication updates */\n eventBus: WorkspaceEventBus\n /** Any config options required for the OAuth2 flow */\n options?: OAuth2Options\n /** Type of the document the schemes belong to, used to label the missing-type warning */\n documentType?: 'openapi' | 'asyncapi'\n}>()\n\nconst emits = defineEmits<{\n (\n e: 'update:selectedScopes',\n payload: Omit<ApiReferenceEvents['auth:update:selected-scopes'], 'meta'>,\n ): void\n (e: 'upsert:scope', payload: ApiReferenceEvents['auth:upsert:scopes']): void\n (e: 'delete:scope', payload: ApiReferenceEvents['auth:delete:scopes']): void\n}>()\n\nconst { translate } = useLocalization()\n\ntype SecurityItem = {\n scheme: SecuritySchemeObjectSecret | undefined\n name: string\n scopes: string[]\n /** Ordered, non-hidden oauth2/openIdConnect flow keys for this scheme (empty for other types). */\n visibleFlowKeys: (keyof OAuthFlowsObjectSecret)[]\n}\n\n/**\n * Human-readable name of the document type.\n * Used in the missing-type warning so it points at the correct document\n * (e.g. \"AsyncAPI\") instead of always naming OpenAPI.\n */\nconst documentTypeLabel = computed<string>(() =>\n getDocumentTypeLabel(documentType),\n)\n\n/**\n * Resolves security schemes from the OpenAPI document and combines them with their selected scopes.\n * Each item includes the scheme definition, name, and associated scopes.\n */\nconst security = computed<SecurityItem[]>(() =>\n Object.entries(selectedSecuritySchemas).map(([name, scopes = []]) => {\n const scheme = getResolvedRef(securitySchemes[name])\n return {\n scheme,\n name,\n scopes,\n // Compute the visible, ordered flow keys once per scheme so the tabs, the label, and the\n // active-flow tracking all agree on the same set (and we do not filter + sort on every access).\n visibleFlowKeys:\n scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\n ? getVisibleOrderedFlowKeys(scheme.flows)\n : [],\n }\n }),\n)\n\n/** Tracks which OAuth2 flow is currently active when multiple flows are available. */\nconst activeFlow = ref<string>('')\n\n/**\n * Keeps the selected flow in sync with the currently visible flow keys. Validating against the\n * visible set (not every declared flow) means a selection that becomes hidden — e.g. the document\n * is updated to mark the active flow with `x-scalar-ignore` — resets, so the default (first visible)\n * flow activates instead of leaving no tab selected.\n */\nconst selectedFlow = computed<string>(() => {\n const visibleFlowKeys = security.value.flatMap((item) => item.visibleFlowKeys)\n\n return visibleFlowKeys.some((key) => key === activeFlow.value)\n ? activeFlow.value\n : ''\n})\n\nconst setActiveFlow = (flow: string): void => {\n activeFlow.value = flow\n}\n\n/** Determines if multiple auth schemes are configured, which affects the UI layout. */\nconst hasMultipleSchemes = computed<boolean>(() => security.value.length > 1)\n\n/**\n * Generates a human-readable label for the security scheme.\n * Intentionally omits the description here — it is rendered separately as\n * rich text via ScalarMarkdownSummary so markdown formatting is preserved.\n */\nconst generateLabel = (\n name: string,\n scheme: SecuritySchemeObjectSecret,\n): string => {\n const capitalizedName = capitalize(name)\n\n switch (scheme.type) {\n case 'apiKey':\n return `${capitalizedName}: ${scheme.in}`\n\n case 'openIdConnect':\n case 'oauth2': {\n const firstFlow = getVisibleOrderedFlowKeys(scheme.flows)[0]\n const currentFlow = selectedFlow.value || firstFlow\n if (!currentFlow) {\n return capitalizedName\n }\n return `${capitalizedName}: ${currentFlow}`\n }\n\n case 'http':\n return `${capitalizedName}: ${scheme.scheme}`\n\n default:\n return capitalizedName\n }\n}\n\n/**\n * Whether an API key scheme exposes an editable parameter name.\n *\n * OpenAPI `apiKey` and AsyncAPI `httpApiKey` (normalized to `apiKey`) name a query/header/cookie\n * parameter, so the Name input is shown. AsyncAPI `apiKey` places the key in the broker `user` or\n * `password` slot and has no parameter name, so the Name input is hidden and only the value is asked for.\n */\nconst apiKeyHasName = (scheme: { in?: string }): boolean =>\n scheme.in !== 'user' && scheme.in !== 'password'\n\n/**\n * The scheme's type when it is one we do not render inputs for (a type outside both the OpenAPI\n * and AsyncAPI security scheme unions). Read through a helper so the fallback template branch,\n * where the scheme type is narrowed to `never` after the supported cases, can still surface the type.\n */\nconst getUnsupportedSchemeType = (\n scheme: SecurityItem['scheme'],\n): string | undefined => scheme?.type\n\n/**\n * Determines if an OAuth2 flow tab should be active.\n * The first flow is active by default if no flow is explicitly selected.\n */\nconst isFlowActive = (flowKey: string, index: number): boolean =>\n selectedFlow.value === flowKey || (index === 0 && !selectedFlow.value)\n\n/** Computes the container class for static display mode. */\nconst getStaticBorderClass = (): string | false => isStatic && 'border-t'\n\nconst handleHttpSecretsUpdate = (\n payload: Omit<Partial<SecretsHttp>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'http', ...payload },\n name,\n })\n\nconst handleApiKeySecretsUpdate = (\n payload: Omit<Partial<SecretsApiKey>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\nconst handleApiKeySecuritySchemeUpdate = (\n payload: Omit<Partial<ApiKeyObject>, 'type'>,\n name: string,\n): void =>\n eventBus.emit('auth:update:security-scheme', {\n payload: { type: 'apiKey', ...payload },\n name,\n })\n\n/** Handles scope selection updates for OAuth2 */\nconst handleScopesUpdate = (\n name: string,\n event: { scopes?: string[]; scope?: string; selected?: boolean },\n): void => {\n emits('update:selectedScopes', {\n id: Object.keys(selectedSecuritySchemas),\n name,\n ...event,\n })\n}\n\n/** Handles scope-definition upserts (add / rename / description change) */\nconst handleScopeUpsert = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:upsert:scopes'], 'name'>,\n): void => {\n emits('upsert:scope', { ...event, name })\n}\n\n/** Handles scope-definition deletes */\nconst handleScopeDelete = (\n name: string,\n event: Omit<ApiReferenceEvents['auth:delete:scopes'], 'name'>,\n): void => {\n emits('delete:scope', { ...event, name })\n}\n\n/**\n * Computes dynamic classes for OAuth2 flow tabs based on active state.\n */\nconst getFlowTabClasses = (flowKey: string, index: number): string => {\n const baseClasses =\n 'floating-bg text-c-3 relative cursor-pointer border-b border-transparent py-1 text-base font-medium'\n const activeClasses = '!text-c-1 !rounded-none border-b !border-current'\n\n return isFlowActive(flowKey, index)\n ? `${baseClasses} ${activeClasses} ${isStatic ? 'opacity-100' : ''}`\n : baseClasses\n}\n\n/**\n * OAuth2 token-acquisition target (an oauth2 scheme with an interactive grant) sourced from\n * the merged schemes. When the active scheme is HTTP bearer, this powers the inline\n * \"Authorize via OAuth2\" shortcut: the flow's bearer token is written onto the bearer scheme,\n * so the panel never switches to oauth2.\n *\n * The shortcut is purely a convenience, so it is offered for any interactive oauth2 scheme —\n * including one that is also independently selectable in the dropdown (e.g. Scalar Galaxy's\n * `oAuth2`). Whether that oauth2 scheme is *hidden* from the dropdown is a separate decision made\n * in the selector; here we only surface the shortcut.\n */\nconst oauth2Target = computed(() => getOauth2AcquisitionTarget(securitySchemes))\n\n/** Resolved oauth2 scheme object, for embedding its config form behind the gear. */\nconst oauth2Scheme = computed(() =>\n oauth2Target.value\n ? getResolvedRef(securitySchemes[oauth2Target.value.name])\n : undefined,\n)\n\nconst acquisitionLoader = useLoadingState()\nconst { toast } = useToasts()\nconst configModal = useModal()\n/** Bearer scheme that opened the config modal, so its Authorize callback targets it. */\nconst configBearerName = ref<string | undefined>()\n\n/** Runs the OAuth2 flow and writes the resulting bearer token onto the bearer scheme. */\nconst handleAcquisitionAuthorize = async (\n bearerName: string,\n): Promise<void> => {\n const target = oauth2Target.value\n if (!target || acquisitionLoader.isLoading) {\n return\n }\n acquisitionLoader.start()\n const [error] = await runOAuth2Authorize({\n eventBus,\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flows: target.flows,\n flowType: target.flowType,\n scopes: target.scopes,\n server,\n proxyUrl,\n environment,\n options,\n })\n await acquisitionLoader.clear()\n if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToauthorize'),\n 'error',\n )\n }\n}\n\n/** Refreshes the OAuth2 token and rewrites it onto the bearer scheme. */\nconst handleAcquisitionRefresh = async (bearerName: string): Promise<void> => {\n const target = oauth2Target.value\n // Only the authorization-code flow carries a refresh token; implicit can't be refreshed.\n if (\n !target ||\n target.flowType !== 'authorizationCode' ||\n acquisitionLoader.isLoading\n ) {\n return\n }\n acquisitionLoader.start()\n const [error, tokens] = await refreshOauth2Token(\n target.flows,\n target.flowType,\n proxyUrl,\n server,\n getEnvironmentVariables(environment),\n options?.customFetch,\n )\n await acquisitionLoader.clear()\n if (tokens?.accessToken) {\n storeOAuth2Tokens(eventBus, {\n bearerSchemeName: bearerName,\n oauth2Name: target.name,\n flowType: target.flowType,\n tokens,\n })\n } else if (error) {\n toast(\n error?.message ?? translate('apiClient.requestAuthTab.failedToRefresh'),\n 'error',\n )\n }\n}\n\nconst openAcquisitionConfig = (bearerName: string): void => {\n configBearerName.value = bearerName\n configModal.show()\n}\n\n/** Closes the config modal and runs Authorize against the bearer scheme that opened it. */\nconst handleConfigAuthorize = (): void => {\n const bearerName = configBearerName.value\n configModal.hide()\n if (bearerName) {\n void handleAcquisitionAuthorize(bearerName)\n }\n}\n</script>\n<template>\n <template\n v-for=\"{ scheme, name, scopes, visibleFlowKeys } in security\"\n :key=\"name\">\n <!--\n Header row for AND'ed schemes: label (bold) and description (rich text) are\n combined.\n -->\n <DataTableRow v-if=\"hasMultipleSchemes && scheme\">\n <DataTableCell\n :aria-label=\"generateLabel(name, scheme)\"\n class=\"max-h-[auto]\">\n <div class=\"bg-b-1 min-w-0 flex-1 px-3 py-1.25\">\n <p class=\"text-c-1 leading-5.5 font-medium\">\n {{ generateLabel(name, scheme) }}\n </p>\n <ScalarMarkdownSummary\n v-if=\"scheme.description\"\n class=\"auth-description text-c-2 w-full\"\n :value=\"scheme.description\" />\n </div>\n </DataTableCell>\n </DataTableRow>\n\n <!-- Description: shown for single auth schemes with descriptions -->\n <DataTableRow v-if=\"scheme?.description && !hasMultipleSchemes\">\n <DataTableCell\n :aria-label=\"scheme.description\"\n class=\"max-h-[auto]\">\n <ScalarMarkdownSummary\n class=\"auth-description bg-b-1 text-c-2 min-w-0 flex-1 px-3 py-1.25\"\n :value=\"scheme.description\" />\n </DataTableCell>\n </DataTableRow>\n\n <!-- HTTP Authentication -->\n <template v-if=\"scheme?.type === 'http'\">\n <!-- Bearer Token -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer'\">\n <RequestAuthDataTableInput\n canReset\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n :placeholder=\"translate('apiClient.requestAuthTab.token')\"\n type=\"password\"\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-token',\n })\n \"\n @update:modelValue=\"\n (v) => handleHttpSecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.bearerToken') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n\n <!-- OAuth2 token-acquisition shortcut (shown when an interactive oauth2 flow exists) -->\n <DataTableRow v-if=\"scheme.scheme === 'bearer' && oauth2Target\">\n <div class=\"flex h-8 items-center gap-2 border-t pl-3 text-base\">\n <span class=\"text-c-1 mr-auto\">{{\n translate('apiClient.requestAuthTab.getAToken')\n }}</span>\n <ScalarButton\n class=\"text-c-1 px-3 py-1\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n type=\"button\"\n variant=\"gradient\"\n @click=\"handleAcquisitionAuthorize(name)\">\n {{\n translate('apiClient.requestAuthTab.authorizeVia', {\n name: oauth2Target.name,\n })\n }}\n </ScalarButton>\n <ScalarButton\n v-if=\"\n scheme['x-scalar-secret-token'] &&\n oauth2Target.flowType === 'authorizationCode'\n \"\n class=\"px-3 py-1\"\n :disabled=\"acquisitionLoader.isLoading\"\n size=\"sm\"\n type=\"button\"\n variant=\"outlined\"\n @click=\"handleAcquisitionRefresh(name)\">\n {{ translate('apiClient.requestAuthTab.refresh') }}\n </ScalarButton>\n <!-- Sized and inset like the password toggle in the row above so the two icons line up -->\n <ScalarIconButton\n class=\"mr-1.25 h-6 w-6 p-1.25\"\n :icon=\"ScalarIconGear\"\n :label=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \"\n @click=\"openAcquisitionConfig(name)\" />\n </div>\n </DataTableRow>\n\n <!-- HTTP Basic Authentication -->\n <template v-else-if=\"scheme?.scheme === 'basic'\">\n <DataTableRow>\n <RequestAuthDataTableInput\n canReset\n class=\"text-c-2\"\n :environment\n :modelValue=\"scheme['x-scalar-secret-username']\"\n placeholder=\"janedoe\"\n required\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-username',\n })\n \"\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-username': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.username') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n canReset\n :environment\n :modelValue=\"scheme['x-scalar-secret-password']\"\n placeholder=\"********\"\n type=\"password\"\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-password',\n })\n \"\n @update:modelValue=\"\n (v) =>\n handleHttpSecretsUpdate({ 'x-scalar-secret-password': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.password') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n </template>\n\n <!-- API Key Authentication -->\n <template v-else-if=\"scheme?.type === 'apiKey'\">\n <DataTableRow v-if=\"apiKeyHasName(scheme)\">\n <RequestAuthDataTableInput\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme.name ?? ''\"\n placeholder=\"api-key\"\n @update:modelValue=\"\n (v) => handleApiKeySecuritySchemeUpdate({ name: v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.name') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow>\n <RequestAuthDataTableInput\n canReset\n :containerClass=\"\n apiKeyHasName(scheme) ? undefined : getStaticBorderClass()\n \"\n :environment\n :modelValue=\"scheme['x-scalar-secret-token']\"\n placeholder=\"QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT\"\n type=\"password\"\n @reset=\"\n eventBus.emit('auth:reset:security-scheme-secret', {\n name,\n field: 'x-scalar-secret-token',\n })\n \"\n @update:modelValue=\"\n (v) =>\n handleApiKeySecretsUpdate({ 'x-scalar-secret-token': v }, name)\n \">\n {{ translate('apiClient.requestAuthTab.value') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n </template>\n\n <!-- OAuth 2.0 / OpenID Connect Authentication -->\n <template\n v-else-if=\"scheme?.type === 'oauth2' || scheme?.type === 'openIdConnect'\">\n <OAuth2Metadata\n v-if=\"\n scheme.type === 'oauth2' && (!isStatic || scheme.oauth2MetadataUrl)\n \"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :name\n :proxyUrl\n :scheme />\n\n <!-- OpenID Connect -->\n <OpenIDConnect\n v-if=\"scheme?.type === 'openIdConnect' && !visibleFlowKeys.length\"\n :customFetch=\"options?.customFetch\"\n :environment\n :eventBus\n :getStaticBorderClass\n :name\n :proxyUrl\n :scheme />\n\n <!-- Flow selector tabs: shown when multiple visible flows are available -->\n <DataTableRow v-if=\"visibleFlowKeys.length > 1\">\n <div class=\"flex min-h-8 border-t text-base\">\n <div class=\"flex h-8 max-w-full gap-2.5 overflow-x-auto px-3\">\n <button\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\"\n :class=\"getFlowTabClasses(key, ind)\"\n type=\"button\"\n @click=\"setActiveFlow(key)\">\n <span class=\"relative z-10\">{{ key }}</span>\n </button>\n </div>\n </div>\n </DataTableRow>\n\n <!-- OAuth2 flow configuration -->\n <template\n v-for=\"(key, ind) in visibleFlowKeys\"\n :key=\"key\">\n <OAuth2\n v-if=\"scheme.flows && isFlowActive(key, ind)\"\n :environment\n :eventBus\n :flows=\"scheme.flows\"\n :name\n :options\n :proxyUrl\n :scheme\n :selectedScopes=\"scopes\"\n :server\n :type=\"key\"\n @delete:scope=\"(event) => handleScopeDelete(name, event)\"\n @update:selectedScopes=\"(event) => handleScopesUpdate(name, event)\"\n @upsert:scope=\"(event) => handleScopeUpsert(name, event)\" />\n </template>\n </template>\n\n <!-- Browser WebSocket connections cannot apply these broker credentials. -->\n <div\n v-else-if=\"\n scheme?.type === 'userPassword' ||\n scheme?.type === 'plain' ||\n scheme?.type === 'scramSha256' ||\n scheme?.type === 'scramSha512' ||\n scheme?.type === 'X509' ||\n scheme?.type === 'symmetricEncryption' ||\n scheme?.type === 'asymmetricEncryption' ||\n scheme?.type === 'gssapi'\n \"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.unsupportedCredentials') }}\n </div>\n\n <!-- Mutual TLS credentials are chosen during the browser-managed TLS handshake. -->\n <div\n v-else-if=\"scheme?.type === 'mutualTLS'\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{ translate('apiClient.requestAuthTab.mutualTlsHint') }}\n </div>\n\n <!-- Scheme has a type we do not render inputs for -->\n <div\n v-else-if=\"getUnsupportedSchemeType(scheme)\"\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.unsupportedType', {\n type: getUnsupportedSchemeType(scheme) ?? '',\n })\n }}\n </div>\n\n <!-- Scheme is missing type -->\n <div\n v-else\n class=\"text-c-3 flex items-center justify-center border-t p-4 px-4 text-center text-xs text-balance\">\n {{\n translate('apiClient.requestAuthTab.missingType', {\n type: documentTypeLabel,\n })\n }}\n </div>\n </template>\n\n <!-- OAuth2 configuration modal (opened from the bearer scheme's gear) -->\n <ScalarModal\n v-if=\"oauth2Target && oauth2Scheme\"\n size=\"sm\"\n :state=\"configModal\"\n :title=\"\n translate('apiClient.requestAuthTab.configure', {\n name: oauth2Target.name,\n })\n \">\n <DataTable\n :columns=\"['']\"\n presentational>\n <OAuth2\n :environment\n :eventBus\n :flows=\"oauth2Target.flows\"\n hideActions\n :name=\"oauth2Target.name\"\n :options\n :proxyUrl\n :scheme=\"oauth2Scheme\"\n :selectedScopes=\"oauth2Target.scopes\"\n :server\n :type=\"oauth2Target.flowType\"\n @delete:scope=\"(event) => handleScopeDelete(oauth2Target!.name, event)\"\n @update:selectedScopes=\"\n (event) => handleScopesUpdate(oauth2Target!.name, event)\n \"\n @upsert:scope=\"\n (event) => handleScopeUpsert(oauth2Target!.name, event)\n \" />\n </DataTable>\n <div class=\"flex h-8 items-center justify-end gap-2 border-t\">\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"configModal.hide()\">\n {{ translate('apiClient.requestAuthTab.cancel') }}\n </ScalarButton>\n <ScalarButton\n class=\"p-0 px-2 py-0.5\"\n :loader=\"acquisitionLoader\"\n size=\"sm\"\n @click=\"handleConfigAuthorize\">\n {{ translate('apiClient.requestAuthTab.authorize') }}\n </ScalarButton>\n </div>\n </ScalarModal>\n</template>\n"],"mappings":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A,MAAM,aAAA,MAAa;MACnB,kBAAY,OAAA,OAAA,OAAA,MAAG,UAAU,kBAAkB,aAAA,MAAc,MAAM,KAAK;MACpE,2BAAqB,OAAA,OAAA,OAAA,MAAc,UAAU,mBAAmB,aAAA,MAAc,MAAM,KAAK;MAGzF,kBAAY,OAAA,OAAA,OAAA,MAAc,UAAU,kBAAkB,aAAA,MAAc,MAAM,KAAK;;;;;;;;;;;;;;QAIpF,mBAeM,OAfN,aAeM,CAdJ,YAMe,MAAA,YAAA,GAAA;KALb,OAAM;KACN,MAAK;KACL,SAAQ;KACP,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,MAAA,WAAA,CAAW,CAAC,KAAI;;4BAC0B,CAAA,gBAAA,gBAA/C,MAAA,SAAA,CAAS,CAAA,iCAAA,CAAA,GAAA,CAAA,CAAA,CAAA;;QAEd,YAMe,MAAA,YAAA,GAAA;KALb,OAAM;KACL,QAAQ,MAAA,iBAAA;KACT,MAAK;KACJ,SAAO;;4BAC6C,CAAA,gBAAA,gBAAlD,MAAA,SAAA,CAAS,CAAA,oCAAA,CAAA,GAAA,CAAA,CAAA,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-device-authorization.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAK3E,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAA;AACjG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAEhG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAGnF,OAAO,EAAE,KAAK,YAAY,EAAuB,MAAM,SAAS,CAAA;AAOhE,uFAAuF;AACvF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAA;CACjC,CAAA;AAED,6CAA6C;AAC7C,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,EAAE,CAAC,MAAM,EAAE,yBAAyB,KAAK,IAAI,CAAA;IACrD,MAAM,EAAE,WAAW,CAAA;CACpB,CAAA;AA4BD,oGAAoG;AACpG,eAAO,MAAM,eAAe,GAC1B,MAAM,kCAAkC,EACxC,QAAQ,MAAM,EAAE,EAChB,QAAQ,YAAY,GAAG,IAAI,EAC3B,UAAU,MAAM,EAChB,aAAa,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,cAAa,WAAmB,EAChC,UAAU,0BAA0B,KACnC,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CA4HrC,CAAA"}
1
+ {"version":3,"file":"oauth-device-authorization.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAK3E,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAA;AACjG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAEhG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAGnF,OAAO,EAAE,KAAK,YAAY,EAAuB,MAAM,SAAS,CAAA;AAOhE,uFAAuF;AACvF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAA;CACjC,CAAA;AAED,6CAA6C;AAC7C,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,EAAE,CAAC,MAAM,EAAE,yBAAyB,KAAK,IAAI,CAAA;IACrD,MAAM,EAAE,WAAW,CAAA;CACpB,CAAA;AA4BD,oGAAoG;AACpG,eAAO,MAAM,eAAe,GAC1B,MAAM,kCAAkC,EACxC,QAAQ,MAAM,EAAE,EAChB,QAAQ,YAAY,GAAG,IAAI,EAC3B,UAAU,MAAM,EAChB,aAAa,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,cAAa,WAAmB,EAChC,UAAU,0BAA0B,KACnC,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAgIrC,CAAA"}
@@ -33,6 +33,8 @@ var authorizeDevice = async (flow, scopes, server, proxyUrl, environment, custom
33
33
  if (!options) throw new Error("Device authorization requires a verification prompt");
34
34
  const resolveValue = (value) => replaceEnvVariables(value, environment);
35
35
  const endpoint = (value) => redirectToProxy(proxyUrl, makeUrlAbsolute(resolveValue(value), getActiveServerBase(server, environment)));
36
+ const tokenUrl = flow["x-scalar-secret-token-url"] ?? flow.tokenUrl;
37
+ if (!tokenUrl.trim()) throw new Error("Token URL is required");
36
38
  const clientId = resolveValue(flow["x-scalar-secret-client-id"]);
37
39
  const clientSecret = resolveValue(flow["x-scalar-secret-client-secret"]);
38
40
  const headers = { "Content-Type": "application/x-www-form-urlencoded" };
@@ -74,7 +76,7 @@ var authorizeDevice = async (flow, scopes, server, proxyUrl, environment, custom
74
76
  await waitForPoll(Math.min(interval, expiresAt - Date.now()), signal);
75
77
  signal.throwIfAborted();
76
78
  if (Date.now() >= expiresAt) throw new Error("Device authorization expired");
77
- const tokenResponse = await customFetch(endpoint(flow["x-scalar-secret-token-url"] || flow.tokenUrl), {
79
+ const tokenResponse = await customFetch(endpoint(tokenUrl), {
78
80
  method: "POST",
79
81
  headers,
80
82
  body,
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-device-authorization.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.ts"],"sourcesContent":["import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error'\nimport { isObject } from '@scalar/helpers/object/is-object'\nimport { replaceEnvVariables } from '@scalar/helpers/regex/replace-variables'\nimport { makeUrlAbsolute } from '@scalar/helpers/url/make-url-absolute'\nimport { redirectToProxy } from '@scalar/helpers/url/redirect-to-proxy'\nimport type { OAuthFlowDeviceAuthorizationSecret } from '@scalar/workspace-store/request-example'\nimport type { ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\n\nimport type { CustomFetch } from '@/v2/blocks/operation-block/helpers/send-request'\n\nimport { isAllowedOAuthUrl } from './is-allowed-oauth-url'\nimport { type OAuth2Tokens, getActiveServerBase } from './oauth'\nimport { oauthClientAuthorization } from './oauth-client-authorization'\n\nconst REQUEST_TIMEOUT_MS = 30_000\n// Maximum delay supported by the browser timer API.\nconst MAX_TIMEOUT_MS = 2_147_483_647\n\n/** Information the user needs to approve a device without exposing the device code. */\nexport type DeviceAuthorizationPrompt = {\n userCode: string\n verificationUri: string\n verificationUriComplete?: string\n}\n\n/** Device flow UI and cancellation hooks. */\nexport type DeviceAuthorizationOptions = {\n onPrompt: (prompt: DeviceAuthorizationPrompt) => void\n signal: AbortSignal\n}\n\n/** Waits between polls, releasing the timer immediately when cancelled or expired. */\nconst waitForPoll = (milliseconds: number, signal: AbortSignal): Promise<void> =>\n new Promise((resolve, reject) => {\n signal.throwIfAborted()\n const abort = (): void => {\n clearTimeout(timer)\n reject(signal.reason)\n }\n const timer = setTimeout(() => {\n signal.removeEventListener('abort', abort)\n resolve()\n }, milliseconds)\n signal.addEventListener('abort', abort, { once: true })\n })\n\nconst verificationUrl = (value: unknown): string => {\n if (typeof value !== 'string') {\n throw new Error('Missing device verification URL')\n }\n const url = new URL(value)\n if (!isAllowedOAuthUrl(url)) {\n throw new Error('Device verification URL must use HTTPS or HTTP for local development URLs')\n }\n return url.href\n}\n\n/** Performs the RFC8628 device grant, respecting expiry, pending responses, and polling backoff. */\nexport const authorizeDevice = async (\n flow: OAuthFlowDeviceAuthorizationSecret,\n scopes: string[],\n server: ServerObject | null,\n proxyUrl: string,\n environment: Record<string, string>,\n customFetch: CustomFetch = fetch,\n options?: DeviceAuthorizationOptions,\n): Promise<ErrorResponse<OAuth2Tokens>> => {\n try {\n if (!options) {\n throw new Error('Device authorization requires a verification prompt')\n }\n const resolveValue = (value: string): string => replaceEnvVariables(value, environment)\n const endpoint = (value: string): string =>\n redirectToProxy(proxyUrl, makeUrlAbsolute(resolveValue(value), getActiveServerBase(server, environment)))\n const clientId = resolveValue(flow['x-scalar-secret-client-id'])\n const clientSecret = resolveValue(flow['x-scalar-secret-client-secret'])\n const headers: Record<string, string> = { 'Content-Type': 'application/x-www-form-urlencoded' }\n const credentials = new URLSearchParams()\n if (clientSecret && flow['x-scalar-credentials-location'] !== 'body') {\n headers.Authorization = oauthClientAuthorization(clientId, clientSecret)\n } else {\n credentials.set('client_id', clientId)\n if (clientSecret) {\n credentials.set('client_secret', clientSecret)\n }\n }\n const deviceBody = new URLSearchParams(credentials)\n if (scopes.length) {\n deviceBody.set('scope', scopes.join(' '))\n }\n const response = await customFetch(endpoint(flow.deviceAuthorizationUrl), {\n method: 'POST',\n headers,\n body: deviceBody,\n signal: AbortSignal.any([options.signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]),\n })\n const data: unknown = await response.json()\n options.signal.throwIfAborted()\n if (!isObject(data)) {\n throw new Error('Invalid device authorization response')\n }\n if (!response.ok) {\n throw new Error(String(data.error_description ?? data.error ?? 'Device authorization failed'))\n }\n if (\n typeof data.device_code !== 'string' ||\n !data.device_code ||\n typeof data.user_code !== 'string' ||\n !data.user_code ||\n typeof data.expires_in !== 'number' ||\n !Number.isFinite(data.expires_in) ||\n data.expires_in <= 0 ||\n (data.interval !== undefined &&\n (typeof data.interval !== 'number' || !Number.isFinite(data.interval) || data.interval < 0))\n ) {\n throw new Error('Invalid device authorization response')\n }\n const lifetime = Math.min(data.expires_in * 1000, MAX_TIMEOUT_MS)\n const expiresAt = Date.now() + lifetime\n const expiry = AbortSignal.timeout(lifetime)\n const signal = AbortSignal.any([options.signal, expiry])\n options.onPrompt({\n userCode: data.user_code,\n verificationUri: verificationUrl(data.verification_uri),\n ...(data.verification_uri_complete\n ? { verificationUriComplete: verificationUrl(data.verification_uri_complete) }\n : {}),\n })\n const body = new URLSearchParams(credentials)\n for (const [key, value] of Object.entries(flow['x-scalar-security-body'] ?? {})) {\n body.set(key, resolveValue(value))\n }\n body.set('grant_type', 'urn:ietf:params:oauth:grant-type:device_code')\n body.set('device_code', data.device_code)\n let interval = typeof data.interval === 'number' ? Math.max(1000, data.interval * 1000) : 5000\n try {\n while (Date.now() < expiresAt) {\n await waitForPoll(Math.min(interval, expiresAt - Date.now()), signal)\n signal.throwIfAborted()\n if (Date.now() >= expiresAt) {\n throw new Error('Device authorization expired')\n }\n // Connection timeouts require a lower polling frequency (RFC8628 section 3.5).\n const tokenResponse = await customFetch(endpoint(flow['x-scalar-secret-token-url'] || flow.tokenUrl), {\n method: 'POST',\n headers,\n body,\n signal: AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]),\n }).catch((error: unknown) => {\n signal.throwIfAborted()\n if (error instanceof Error && error.name === 'TimeoutError') {\n return null\n }\n throw error\n })\n if (!tokenResponse) {\n // Saturating at expiry never schedules an earlier poll: the loop expires instead.\n interval = Math.min(interval * 2, expiresAt - Date.now())\n continue\n }\n const token: unknown = await tokenResponse.json()\n if (!isObject(token)) {\n throw new Error('Invalid device token response')\n }\n if (token.error === 'authorization_pending') {\n continue\n }\n if (token.error === 'slow_down') {\n interval = Math.min(interval + 5000, expiresAt - Date.now())\n continue\n }\n const accessToken = token[flow['x-tokenName'] || 'access_token']\n if (tokenResponse.ok && typeof accessToken === 'string' && accessToken) {\n return [\n null,\n { accessToken, ...(typeof token.refresh_token === 'string' ? { refreshToken: token.refresh_token } : {}) },\n ]\n }\n throw new Error(String(token.error_description ?? token.error ?? 'Failed to get an access token'))\n }\n throw new Error('Device authorization expired')\n } catch (error) {\n if (expiry.aborted && !options.signal.aborted) {\n throw new Error('Device authorization expired')\n }\n throw error\n }\n } catch (error) {\n return [error instanceof Error ? error : new Error('Device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C;IAAG,CAC3G;IAEF,MAAM,IAAI,MAAM,OAAO,MAAM,qBAAqB,MAAM,SAAS,+BAA+B,CAAC;GACnG;GACA,MAAM,IAAI,MAAM,8BAA8B;EAChD,SAAS,OAAO;GACd,IAAI,OAAO,WAAW,CAAC,QAAQ,OAAO,SACpC,MAAM,IAAI,MAAM,8BAA8B;GAEhD,MAAM;EACR;CACF,SAAS,OAAO;EACd,OAAO,CAAC,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,+BAA+B,EAAE,OAAO,MAAM,CAAC,GAAG,IAAI;CAC3G;AACF"}
1
+ {"version":3,"file":"oauth-device-authorization.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/helpers/oauth-device-authorization.ts"],"sourcesContent":["import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error'\nimport { isObject } from '@scalar/helpers/object/is-object'\nimport { replaceEnvVariables } from '@scalar/helpers/regex/replace-variables'\nimport { makeUrlAbsolute } from '@scalar/helpers/url/make-url-absolute'\nimport { redirectToProxy } from '@scalar/helpers/url/redirect-to-proxy'\nimport type { OAuthFlowDeviceAuthorizationSecret } from '@scalar/workspace-store/request-example'\nimport type { ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\n\nimport type { CustomFetch } from '@/v2/blocks/operation-block/helpers/send-request'\n\nimport { isAllowedOAuthUrl } from './is-allowed-oauth-url'\nimport { type OAuth2Tokens, getActiveServerBase } from './oauth'\nimport { oauthClientAuthorization } from './oauth-client-authorization'\n\nconst REQUEST_TIMEOUT_MS = 30_000\n// Maximum delay supported by the browser timer API.\nconst MAX_TIMEOUT_MS = 2_147_483_647\n\n/** Information the user needs to approve a device without exposing the device code. */\nexport type DeviceAuthorizationPrompt = {\n userCode: string\n verificationUri: string\n verificationUriComplete?: string\n}\n\n/** Device flow UI and cancellation hooks. */\nexport type DeviceAuthorizationOptions = {\n onPrompt: (prompt: DeviceAuthorizationPrompt) => void\n signal: AbortSignal\n}\n\n/** Waits between polls, releasing the timer immediately when cancelled or expired. */\nconst waitForPoll = (milliseconds: number, signal: AbortSignal): Promise<void> =>\n new Promise((resolve, reject) => {\n signal.throwIfAborted()\n const abort = (): void => {\n clearTimeout(timer)\n reject(signal.reason)\n }\n const timer = setTimeout(() => {\n signal.removeEventListener('abort', abort)\n resolve()\n }, milliseconds)\n signal.addEventListener('abort', abort, { once: true })\n })\n\nconst verificationUrl = (value: unknown): string => {\n if (typeof value !== 'string') {\n throw new Error('Missing device verification URL')\n }\n const url = new URL(value)\n if (!isAllowedOAuthUrl(url)) {\n throw new Error('Device verification URL must use HTTPS or HTTP for local development URLs')\n }\n return url.href\n}\n\n/** Performs the RFC8628 device grant, respecting expiry, pending responses, and polling backoff. */\nexport const authorizeDevice = async (\n flow: OAuthFlowDeviceAuthorizationSecret,\n scopes: string[],\n server: ServerObject | null,\n proxyUrl: string,\n environment: Record<string, string>,\n customFetch: CustomFetch = fetch,\n options?: DeviceAuthorizationOptions,\n): Promise<ErrorResponse<OAuth2Tokens>> => {\n try {\n if (!options) {\n throw new Error('Device authorization requires a verification prompt')\n }\n const resolveValue = (value: string): string => replaceEnvVariables(value, environment)\n const endpoint = (value: string): string =>\n redirectToProxy(proxyUrl, makeUrlAbsolute(resolveValue(value), getActiveServerBase(server, environment)))\n const tokenUrl = flow['x-scalar-secret-token-url'] ?? flow.tokenUrl\n if (!tokenUrl.trim()) {\n throw new Error('Token URL is required')\n }\n const clientId = resolveValue(flow['x-scalar-secret-client-id'])\n const clientSecret = resolveValue(flow['x-scalar-secret-client-secret'])\n const headers: Record<string, string> = { 'Content-Type': 'application/x-www-form-urlencoded' }\n const credentials = new URLSearchParams()\n if (clientSecret && flow['x-scalar-credentials-location'] !== 'body') {\n headers.Authorization = oauthClientAuthorization(clientId, clientSecret)\n } else {\n credentials.set('client_id', clientId)\n if (clientSecret) {\n credentials.set('client_secret', clientSecret)\n }\n }\n const deviceBody = new URLSearchParams(credentials)\n if (scopes.length) {\n deviceBody.set('scope', scopes.join(' '))\n }\n const response = await customFetch(endpoint(flow.deviceAuthorizationUrl), {\n method: 'POST',\n headers,\n body: deviceBody,\n signal: AbortSignal.any([options.signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]),\n })\n const data: unknown = await response.json()\n options.signal.throwIfAborted()\n if (!isObject(data)) {\n throw new Error('Invalid device authorization response')\n }\n if (!response.ok) {\n throw new Error(String(data.error_description ?? data.error ?? 'Device authorization failed'))\n }\n if (\n typeof data.device_code !== 'string' ||\n !data.device_code ||\n typeof data.user_code !== 'string' ||\n !data.user_code ||\n typeof data.expires_in !== 'number' ||\n !Number.isFinite(data.expires_in) ||\n data.expires_in <= 0 ||\n (data.interval !== undefined &&\n (typeof data.interval !== 'number' || !Number.isFinite(data.interval) || data.interval < 0))\n ) {\n throw new Error('Invalid device authorization response')\n }\n const lifetime = Math.min(data.expires_in * 1000, MAX_TIMEOUT_MS)\n const expiresAt = Date.now() + lifetime\n const expiry = AbortSignal.timeout(lifetime)\n const signal = AbortSignal.any([options.signal, expiry])\n options.onPrompt({\n userCode: data.user_code,\n verificationUri: verificationUrl(data.verification_uri),\n ...(data.verification_uri_complete\n ? { verificationUriComplete: verificationUrl(data.verification_uri_complete) }\n : {}),\n })\n const body = new URLSearchParams(credentials)\n for (const [key, value] of Object.entries(flow['x-scalar-security-body'] ?? {})) {\n body.set(key, resolveValue(value))\n }\n body.set('grant_type', 'urn:ietf:params:oauth:grant-type:device_code')\n body.set('device_code', data.device_code)\n let interval = typeof data.interval === 'number' ? Math.max(1000, data.interval * 1000) : 5000\n try {\n while (Date.now() < expiresAt) {\n await waitForPoll(Math.min(interval, expiresAt - Date.now()), signal)\n signal.throwIfAborted()\n if (Date.now() >= expiresAt) {\n throw new Error('Device authorization expired')\n }\n // Connection timeouts require a lower polling frequency (RFC8628 section 3.5).\n const tokenResponse = await customFetch(endpoint(tokenUrl), {\n method: 'POST',\n headers,\n body,\n signal: AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]),\n }).catch((error: unknown) => {\n signal.throwIfAborted()\n if (error instanceof Error && error.name === 'TimeoutError') {\n return null\n }\n throw error\n })\n if (!tokenResponse) {\n // Saturating at expiry never schedules an earlier poll: the loop expires instead.\n interval = Math.min(interval * 2, expiresAt - Date.now())\n continue\n }\n const token: unknown = await tokenResponse.json()\n if (!isObject(token)) {\n throw new Error('Invalid device token response')\n }\n if (token.error === 'authorization_pending') {\n continue\n }\n if (token.error === 'slow_down') {\n interval = Math.min(interval + 5000, expiresAt - Date.now())\n continue\n }\n const accessToken = token[flow['x-tokenName'] || 'access_token']\n if (tokenResponse.ok && typeof accessToken === 'string' && accessToken) {\n return [\n null,\n { accessToken, ...(typeof token.refresh_token === 'string' ? { refreshToken: token.refresh_token } : {}) },\n ]\n }\n throw new Error(String(token.error_description ?? token.error ?? 'Failed to get an access token'))\n }\n throw new Error('Device authorization expired')\n } catch (error) {\n if (expiry.aborted && !options.signal.aborted) {\n throw new Error('Device authorization expired')\n }\n throw error\n }\n } catch (error) {\n return [error instanceof Error ? error : new Error('Device authorization failed', { cause: error }), null]\n }\n}\n"],"mappings":";;;;;;;;AAcA,IAAM,qBAAqB;AAE3B,IAAM,iBAAiB;;AAgBvB,IAAM,eAAe,cAAsB,WACzC,IAAI,SAAS,SAAS,WAAW;CAC/B,OAAO,eAAe;CACtB,MAAM,cAAoB;EACxB,aAAa,KAAK;EAClB,OAAO,OAAO,MAAM;CACtB;CACA,MAAM,QAAQ,iBAAiB;EAC7B,OAAO,oBAAoB,SAAS,KAAK;EACzC,QAAQ;CACV,GAAG,YAAY;CACf,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;AACxD,CAAC;AAEH,IAAM,mBAAmB,UAA2B;CAClD,IAAI,OAAO,UAAU,UACnB,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,MAAM,IAAI,IAAI,KAAK;CACzB,IAAI,CAAC,kBAAkB,GAAG,GACxB,MAAM,IAAI,MAAM,2EAA2E;C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AAgB;AACtB,kCAAkC;AAClC,UAAU,MAAM;AAChB,+DAA+D;AAC/D,cAAc,YAAY,GAAG,IAAI;AACjC,2EAA2E;AAC3E,uBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;AACjD,gIAAgI;AAChI,cAAa,WAAmB,KAC/B,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CA4FrC,CAAA"}
@@ -65,7 +65,9 @@ var authorizeOauth2 = async (flows, type, selectedScopes, activeServer, proxyUrl
65
65
  customFetch
66
66
  }, activeServer, environmentVariables);
67
67
  const state = (Math.random() + 1).toString(36).substring(2, 10);
68
- const authorizationUrl = makeUrlAbsolute(flows[type]["x-scalar-secret-auth-url"] ?? flows[type].authorizationUrl, getActiveServerBase(activeServer, environmentVariables));
68
+ const authUrl = flows[type]["x-scalar-secret-auth-url"] ?? flows[type].authorizationUrl;
69
+ if (!authUrl.trim()) return [/* @__PURE__ */ new Error("Authorization URL is required"), null];
70
+ const authorizationUrl = makeUrlAbsolute(authUrl, getActiveServerBase(activeServer, environmentVariables));
69
71
  const url = new URL(authorizationUrl);
70
72
  /** Special PKCE state */
71
73
  let pkce = null;
@@ -201,7 +203,9 @@ var authorizeServers = async (flows, type, scopes, { code, pkce, proxyUrl, custo
201
203
  try {
202
204
  const headers = { "Content-Type": "application/x-www-form-urlencoded" };
203
205
  if (!addCredentialsToBody && hasClientSecret) headers.Authorization = oauthClientAuthorization(clientId, clientSecret);
204
- const tokenUrl = makeUrlAbsolute(flow["x-scalar-secret-token-url"] ?? flow.tokenUrl, getActiveServerBase(activeServer, environmentVariables));
206
+ const tokenUrlValue = flow["x-scalar-secret-token-url"] ?? flow.tokenUrl;
207
+ if (!tokenUrlValue.trim()) return [/* @__PURE__ */ new Error("Token URL is required"), null];
208
+ const tokenUrl = makeUrlAbsolute(tokenUrlValue, getActiveServerBase(activeServer, environmentVariables));
205
209
  const responseData = await (await customFetch(shouldUseProxy(proxyUrl, tokenUrl) ? `${proxyUrl}?${new URLSearchParams([["scalar_url", tokenUrl]]).toString()}` : tokenUrl, {
206
210
  method: "POST",
207
211
  headers,
@@ -245,7 +249,9 @@ var refreshOauth2Token = async (flows, type, proxyUrl, activeServer, environment
245
249
  try {
246
250
  const headers = { "Content-Type": "application/x-www-form-urlencoded" };
247
251
  if (!addCredentialsToBody && hasClientSecret) headers.Authorization = oauthClientAuthorization(clientId, clientSecret);
248
- const absoluteRefreshUrl = makeUrlAbsolute(flow.refreshUrl || flow["x-scalar-secret-token-url"] || flow.tokenUrl, getActiveServerBase(activeServer, environmentVariables));
252
+ const refreshUrl = flow.refreshUrl || (flow["x-scalar-secret-token-url"] ?? flow.tokenUrl);
253
+ if (!refreshUrl.trim()) return [/* @__PURE__ */ new Error("Token URL is required"), null];
254
+ const absoluteRefreshUrl = makeUrlAbsolute(refreshUrl, getActiveServerBase(activeServer, environmentVariables));
249
255
  const responseData = await (await customFetch(shouldUseProxy(proxyUrl, absoluteRefreshUrl) ? `${proxyUrl}?${new URLSearchParams([["scalar_url", absoluteRefreshUrl]]).toString()}` : absoluteRefreshUrl, {
250
256
  method: "POST",
251
257
  headers,