123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <template>
- <div class="flex flex-col flex-1">
- <div
- class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-upperSecondaryStickyFold"
- >
- <span class="flex items-center">
- <label class="font-semibold text-secondaryLight">
- {{ $t("authorization.type") }}
- </label>
- <tippy
- ref="authTypeOptions"
- interactive
- trigger="click"
- theme="popover"
- arrow
- >
- <template #trigger>
- <span class="select-wrapper">
- <ButtonSecondary
- class="pr-8 ml-2 rounded-none"
- :label="authName"
- />
- </span>
- </template>
- <SmartItem
- label="None"
- :icon="
- authName === 'None'
- ? 'radio_button_checked'
- : 'radio_button_unchecked'
- "
- :active="authName === 'None'"
- @click.native="
- () => {
- authType = 'none'
- authTypeOptions.tippy().hide()
- }
- "
- />
- <SmartItem
- label="Basic Auth"
- :icon="
- authName === 'Basic Auth'
- ? 'radio_button_checked'
- : 'radio_button_unchecked'
- "
- :active="authName === 'Basic Auth'"
- @click.native="
- () => {
- authType = 'basic'
- authTypeOptions.tippy().hide()
- }
- "
- />
- <SmartItem
- label="Bearer Token"
- :icon="
- authName === 'Bearer'
- ? 'radio_button_checked'
- : 'radio_button_unchecked'
- "
- :active="authName === 'Bearer'"
- @click.native="
- () => {
- authType = 'bearer'
- authTypeOptions.tippy().hide()
- }
- "
- />
- <SmartItem
- label="OAuth 2.0"
- :icon="
- authName === 'OAuth 2.0'
- ? 'radio_button_checked'
- : 'radio_button_unchecked'
- "
- :active="authName === 'OAuth 2.0'"
- @click.native="
- () => {
- authType = 'oauth-2'
- authTypeOptions.tippy().hide()
- }
- "
- />
- <SmartItem
- label="API key"
- :icon="
- authName === 'API key'
- ? 'radio_button_checked'
- : 'radio_button_unchecked'
- "
- :active="authName === 'API key'"
- @click.native="
- () => {
- authType = 'api-key'
- authTypeOptions.tippy().hide()
- }
- "
- />
- </tippy>
- </span>
- <div class="flex">
- <!-- <SmartCheckbox
- :on="!URLExcludes.auth"
- @change="setExclude('auth', !$event)"
- >
- {{ $t("authorization.include_in_url") }}
- </SmartCheckbox> -->
- <SmartCheckbox
- :on="authActive"
- class="px-2"
- @change="authActive = !authActive"
- >
- {{ $t("state.enabled") }}
- </SmartCheckbox>
- <ButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- to="https://docs.hoppscotch.io/features/authorization"
- blank
- :title="$t('app.wiki')"
- svg="help-circle"
- />
- <ButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('action.clear')"
- svg="trash-2"
- @click.native="clearContent"
- />
- </div>
- </div>
- <div
- v-if="authType === 'none'"
- class="flex flex-col items-center justify-center p-4 text-secondaryLight"
- >
- <img
- :src="`/images/states/${$colorMode.value}/login.svg`"
- loading="lazy"
- class="inline-flex flex-col object-contain object-center w-16 h-16 my-4"
- :alt="`${$t('empty.authorization')}`"
- />
- <span class="pb-4 text-center">
- {{ $t("empty.authorization") }}
- </span>
- <ButtonSecondary
- outline
- :label="$t('app.documentation')"
- to="https://docs.hoppscotch.io/features/authorization"
- blank
- svg="external-link"
- reverse
- class="mb-4"
- />
- </div>
- <div v-else class="flex flex-1 border-b border-dividerLight">
- <div class="w-2/3 border-r border-dividerLight">
- <div v-if="authType === 'basic'">
- <div class="flex flex-1 border-b border-dividerLight">
- <SmartEnvInput
- v-model="basicUsername"
- :placeholder="$t('authorization.username')"
- styles="bg-transparent flex flex-1 py-1 px-4"
- />
- </div>
- <div class="flex flex-1 border-b border-dividerLight">
- <SmartEnvInput
- v-model="basicPassword"
- :placeholder="$t('authorization.password')"
- styles="bg-transparent flex flex-1 py-1 px-4"
- />
- </div>
- </div>
- <div v-if="authType === 'bearer'">
- <div class="flex flex-1 border-b border-dividerLight">
- <SmartEnvInput
- v-model="bearerToken"
- placeholder="Token"
- styles="bg-transparent flex flex-1 py-1 px-4"
- />
- </div>
- </div>
- <div v-if="authType === 'oauth-2'">
- <div class="flex flex-1 border-b border-dividerLight">
- <SmartEnvInput
- v-model="oauth2Token"
- placeholder="Token"
- styles="bg-transparent flex flex-1 py-1 px-4"
- />
- </div>
- <HttpOAuth2Authorization />
- </div>
- <div v-if="authType === 'api-key'">
- <div class="flex flex-1 border-b border-dividerLight">
- <SmartEnvInput
- v-model="apiKey"
- placeholder="Key"
- styles="bg-transparent flex flex-1 py-1 px-4"
- />
- </div>
- <div class="flex flex-1 border-b border-dividerLight">
- <SmartEnvInput
- v-model="apiValue"
- placeholder="Value"
- styles="bg-transparent flex flex-1 py-1 px-4"
- />
- </div>
- <div class="flex items-center border-b border-dividerLight">
- <label class="ml-4 text-secondaryLight">
- {{ $t("authorization.pass_key_by") }}
- </label>
- <tippy
- ref="addToOptions"
- interactive
- trigger="click"
- theme="popover"
- arrow
- >
- <template #trigger>
- <span class="select-wrapper">
- <ButtonSecondary
- :label="addTo || $t('state.none')"
- class="pr-8 ml-2 rounded-none"
- />
- </span>
- </template>
- <SmartItem
- :icon="
- addTo === 'Headers'
- ? 'radio_button_checked'
- : 'radio_button_unchecked'
- "
- :active="addTo === 'Headers'"
- :label="'Headers'"
- @click.native="
- () => {
- addTo = 'Headers'
- addToOptions.tippy().hide()
- }
- "
- />
- <SmartItem
- :icon="
- addTo === 'Query params'
- ? 'radio_button_checked'
- : 'radio_button_unchecked'
- "
- :active="addTo === 'Query params'"
- :label="'Query params'"
- @click.native="
- () => {
- addTo = 'Query params'
- addToOptions.tippy().hide()
- }
- "
- />
- </tippy>
- </div>
- </div>
- </div>
- <div
- class="sticky h-full p-4 overflow-auto bg-primary top-upperTertiaryStickyFold min-w-46 max-w-1/3 z-9"
- >
- <div class="pb-2 text-secondaryLight">
- {{ $t("helpers.authorization") }}
- </div>
- <SmartAnchor
- class="link"
- :label="`${$t('authorization.learn')} \xA0 →`"
- to="https://docs.hoppscotch.io/features/authorization"
- blank
- />
- </div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { computed, ref, Ref } from "@nuxtjs/composition-api"
- import {
- HoppGQLAuthAPIKey,
- HoppGQLAuthBasic,
- HoppGQLAuthBearer,
- HoppGQLAuthOAuth2,
- } from "@hoppscotch/data"
- import { pluckRef, useStream } from "~/helpers/utils/composables"
- import { gqlAuth$, setGQLAuth } from "~/newstore/GQLSession"
- const auth = useStream(
- gqlAuth$,
- { authType: "none", authActive: true },
- setGQLAuth
- )
- const authType = pluckRef(auth, "authType")
- const authName = computed(() => {
- if (authType.value === "basic") return "Basic Auth"
- else if (authType.value === "bearer") return "Bearer"
- else if (authType.value === "oauth-2") return "OAuth 2.0"
- else if (authType.value === "api-key") return "API key"
- else return "None"
- })
- const authActive = pluckRef(auth, "authActive")
- const basicUsername = pluckRef(auth as Ref<HoppGQLAuthBasic>, "username")
- const basicPassword = pluckRef(auth as Ref<HoppGQLAuthBasic>, "password")
- const bearerToken = pluckRef(auth as Ref<HoppGQLAuthBearer>, "token")
- const oauth2Token = pluckRef(auth as Ref<HoppGQLAuthOAuth2>, "token")
- const apiKey = pluckRef(auth as Ref<HoppGQLAuthAPIKey>, "key")
- const apiValue = pluckRef(auth as Ref<HoppGQLAuthAPIKey>, "value")
- const addTo = pluckRef(auth as Ref<HoppGQLAuthAPIKey>, "addTo")
- if (typeof addTo.value === "undefined") {
- addTo.value = "Headers"
- apiKey.value = ""
- apiValue.value = ""
- }
- const clearContent = () => {
- auth.value = {
- authType: "none",
- authActive: true,
- }
- }
- const authTypeOptions = ref<any | null>(null)
- const addToOptions = ref<any | null>(null)
- </script>
|