mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
* ⚡ Removing authentication parameter from NDV * ⚡ Added auth type selector to credentials modal * 🔨 Extracting reusable logic to util functions * ⚡ Updating credentials position, adding label for radio buttons * ⚡ Using first node credentials for nodes with single auth options and hiding auth selector UI in that case * ⚡ Fixing credentials modal when opened from credentials page * ⚡ Showing all available credentials in NDV credentials dropdown * ⚡ Updating node credentials dropdown component to show credentials description. Disabling `Credentials of type not found` error in node * ⚡ Moving auth related fields from NDV to credentials modal. Added support for multiple auth fileds * ⚡ Moving NDV fields that authentication depends on to credentials modal * ⚡ Keeping old auth/credentials UI in NDV for HTTP Request and Webhook nodes. Pre-populating credential type for HTTP request node when selected from 'app action' menu * 💄 Use old label and field position for nodes that use old credentials UI in NDV * ⚡ Implementing more generic way to find node's auth fileds * 📚 Adding comments on parameter hiding logic * ⚡ Fixing node auth options logic for multiple auth fields * 👕 Fixing lint errors * 💄 Addressing design review comments * ⚡ Not selecting first auth option when opening new credential dialog * ⚡ Using default credentials name and icon if authentication type is not selected * ⚡ Updating credential data when auth type is changed * ⚡ Setting new credentials type for HTTP Request and Webhook nodes * ⚡ Setting nodes with access when changing auth type * 👕 Fixing lint error * ⚡ Updating active node auth type from credentials modal * ⚡ Syncronizing credentials modal and dropdown * 👕 Fixing linter error * ⚡ Handling credential dropdown UI for multiple credentials * 👕 Removing unused imports * ⚡ Handling auth selection when default auth type is the first option * ⚡ Updating credentials change listening logic * ⚡ Resetting credential data when deleting a credential, disabling 'Details' and 'Sharing' tabs if auth type is not selected * 🐛 Skipping credentials type check when showing mixed credentials in the dropdown and switching credentials type * ⚡ Showing credential modal tabs for saved credentials * ⚡ Preventing renaming credentials when no auth type is selected * 🐛 Fixing credentials modal when opened from credentials page * ⚡ Keeping auth radio buttons selected when switching tabs * ✅ Adding initial batch of credentials NDV tests * ⚡ Updating node auth filed value when new credential type is selected * ⚡ Using all available credential types for current node to sync credential dropdown with modal * ⚡ Sorting mixed credentials by date, simplifying credential dropdown option logic * 🔨 Extracting some reusable logic to utils * ⚡ Improving required vs optional credentials detection and using it to show auth radio buttons * 👕 Fixing lint errors * ✅ Adding more credentials tests * ⚡ Filtering credential options based on authentication type * 🔨 Refactoring credentials and auth utils * ⚡ Updated handling of auth options in credentials modal to work with new logic * 🔨 Getting the terminology in line * 📚 Removing leftover comment * ⚡ Updating node auth filed detection logic to account for different edge-cases * ⚡ Adding Wait node as an exception for new UI * ⚡ Updating NDV display when auth type changes * ⚡ Updating default credentials name when auth type changes * ⚡ Hiding auth settings after credentials are saved * ⚡ Always showing credentials modal menu tabs * ⚡ Improving main auth field detection logic so it doesn't account for authentication fields which can have `none` value * ⚡ Restoring accidentally deleted not existing credential issue logic * ⚡ Updating other nodes when deleted credentials have been updated * ⚡ Using filtered auth type list to show or hide radio buttons section in credentials modal * 👕 Addressing lint error * 👌 Addressing PR review feedback * 👕 Fixing lint issues * ⚡ Updating main auth filed detection logic so it checks full dependency path to determine if the field is required or optional * 👌 Addressing the rest of PR feedback * ✅ Updating credential tests * ⚡ Resetting credential data on authentication type change * ⚡ Created AuthTypeSelector component * 👌 Addressing PR comments * ⚡ Not resetting overwritten credential properties when changing auth type * ⚡ Hiding auth selector section if there are no options to show
368 lines
10 KiB
Vue
368 lines
10 KiB
Vue
<template>
|
|
<div :class="$style.container" data-test-id="node-credentials-config-container">
|
|
<banner
|
|
v-show="showValidationWarning"
|
|
theme="danger"
|
|
:message="
|
|
$locale.baseText(
|
|
`credentialEdit.credentialConfig.pleaseCheckTheErrorsBelow${
|
|
credentialPermissions.isOwner ? '' : '.sharee'
|
|
}`,
|
|
{ interpolate: { owner: credentialOwnerName } },
|
|
)
|
|
"
|
|
/>
|
|
|
|
<banner
|
|
v-if="authError && !showValidationWarning"
|
|
theme="danger"
|
|
:message="
|
|
$locale.baseText(
|
|
`credentialEdit.credentialConfig.couldntConnectWithTheseSettings${
|
|
credentialPermissions.isOwner ? '' : '.sharee'
|
|
}`,
|
|
{ interpolate: { owner: credentialOwnerName } },
|
|
)
|
|
"
|
|
:details="authError"
|
|
:buttonLabel="$locale.baseText('credentialEdit.credentialConfig.retry')"
|
|
buttonLoadingLabel="Retrying"
|
|
:buttonTitle="$locale.baseText('credentialEdit.credentialConfig.retryCredentialTest')"
|
|
:buttonLoading="isRetesting"
|
|
@click="$emit('retest')"
|
|
/>
|
|
|
|
<banner
|
|
v-show="showOAuthSuccessBanner && !showValidationWarning"
|
|
theme="success"
|
|
:message="$locale.baseText('credentialEdit.credentialConfig.accountConnected')"
|
|
:buttonLabel="$locale.baseText('credentialEdit.credentialConfig.reconnect')"
|
|
:buttonTitle="$locale.baseText('credentialEdit.credentialConfig.reconnectOAuth2Credential')"
|
|
@click="$emit('oauth')"
|
|
>
|
|
<template #button>
|
|
<p
|
|
v-text="`${$locale.baseText('credentialEdit.credentialConfig.reconnect')}:`"
|
|
:class="$style.googleReconnectLabel"
|
|
/>
|
|
<GoogleAuthButton v-if="isGoogleOAuthType" @click="$emit('oauth')" />
|
|
</template>
|
|
</banner>
|
|
|
|
<banner
|
|
v-show="testedSuccessfully && !showValidationWarning"
|
|
theme="success"
|
|
:message="$locale.baseText('credentialEdit.credentialConfig.connectionTestedSuccessfully')"
|
|
:buttonLabel="$locale.baseText('credentialEdit.credentialConfig.retry')"
|
|
:buttonLoadingLabel="$locale.baseText('credentialEdit.credentialConfig.retrying')"
|
|
:buttonTitle="$locale.baseText('credentialEdit.credentialConfig.retryCredentialTest')"
|
|
:buttonLoading="isRetesting"
|
|
@click="$emit('retest')"
|
|
/>
|
|
|
|
<template v-if="credentialPermissions.updateConnection">
|
|
<n8n-notice v-if="documentationUrl && credentialProperties.length" theme="warning">
|
|
{{ $locale.baseText('credentialEdit.credentialConfig.needHelpFillingOutTheseFields') }}
|
|
<span class="ml-4xs">
|
|
<n8n-link :to="documentationUrl" size="small" bold @click="onDocumentationUrlClick">
|
|
{{ $locale.baseText('credentialEdit.credentialConfig.openDocs') }}
|
|
</n8n-link>
|
|
</span>
|
|
</n8n-notice>
|
|
|
|
<AuthTypeSelector
|
|
v-if="showAuthTypeSelector && isNewCredential"
|
|
:credentialType="credentialType"
|
|
@authTypeChanged="onAuthTypeChange"
|
|
/>
|
|
|
|
<CopyInput
|
|
v-if="isOAuthType && credentialProperties.length"
|
|
:label="$locale.baseText('credentialEdit.credentialConfig.oAuthRedirectUrl')"
|
|
:value="oAuthCallbackUrl"
|
|
:copyButtonText="$locale.baseText('credentialEdit.credentialConfig.clickToCopy')"
|
|
:hint="
|
|
$locale.baseText('credentialEdit.credentialConfig.subtitle', { interpolate: { appName } })
|
|
"
|
|
:toastTitle="
|
|
$locale.baseText('credentialEdit.credentialConfig.redirectUrlCopiedToClipboard')
|
|
"
|
|
/>
|
|
</template>
|
|
<enterprise-edition v-else :features="[EnterpriseEditionFeature.Sharing]">
|
|
<div class="ph-no-capture">
|
|
<n8n-info-tip :bold="false">
|
|
{{
|
|
$locale.baseText('credentialEdit.credentialEdit.info.sharee', {
|
|
interpolate: { credentialOwnerName },
|
|
})
|
|
}}
|
|
</n8n-info-tip>
|
|
</div>
|
|
</enterprise-edition>
|
|
|
|
<CredentialInputs
|
|
v-if="credentialType && credentialPermissions.updateConnection"
|
|
:credentialData="credentialData"
|
|
:credentialProperties="credentialProperties"
|
|
:documentationUrl="documentationUrl"
|
|
:showValidationWarnings="showValidationWarning"
|
|
@change="onDataChange"
|
|
/>
|
|
|
|
<OauthButton
|
|
v-if="
|
|
isOAuthType &&
|
|
requiredPropertiesFilled &&
|
|
!isOAuthConnected &&
|
|
credentialPermissions.isOwner
|
|
"
|
|
:isGoogleOAuthType="isGoogleOAuthType"
|
|
@click="$emit('oauth')"
|
|
/>
|
|
|
|
<n8n-text v-if="isMissingCredentials" color="text-base" size="medium">
|
|
{{ $locale.baseText('credentialEdit.credentialConfig.missingCredentialType') }}
|
|
</n8n-text>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { ICredentialType, INodeTypeDescription } from 'n8n-workflow';
|
|
import { getAppNameFromCredType, isCommunityPackageName } from '@/utils';
|
|
|
|
import Banner from '../Banner.vue';
|
|
import CopyInput from '../CopyInput.vue';
|
|
import CredentialInputs from './CredentialInputs.vue';
|
|
import OauthButton from './OauthButton.vue';
|
|
import { restApi } from '@/mixins/restApi';
|
|
import { addCredentialTranslation } from '@/plugins/i18n';
|
|
import mixins from 'vue-typed-mixins';
|
|
import { BUILTIN_CREDENTIALS_DOCS_URL, DOCS_DOMAIN, EnterpriseEditionFeature } from '@/constants';
|
|
import { IPermissions } from '@/permissions';
|
|
import { mapStores } from 'pinia';
|
|
import { useUIStore } from '@/stores/ui';
|
|
import { useWorkflowsStore } from '@/stores/workflows';
|
|
import { useRootStore } from '@/stores/n8nRootStore';
|
|
import { useNDVStore } from '@/stores/ndv';
|
|
import { useCredentialsStore } from '@/stores/credentials';
|
|
import { useNodeTypesStore } from '@/stores/nodeTypes';
|
|
import { ICredentialsResponse, IUpdateInformation, NodeAuthenticationOption } from '@/Interface';
|
|
import ParameterInputFull from '@/components/ParameterInputFull.vue';
|
|
import AuthTypeSelector from '@/components/CredentialEdit/AuthTypeSelector.vue';
|
|
import GoogleAuthButton from './GoogleAuthButton.vue';
|
|
|
|
export default mixins(restApi).extend({
|
|
name: 'CredentialConfig',
|
|
components: {
|
|
AuthTypeSelector,
|
|
Banner,
|
|
CopyInput,
|
|
CredentialInputs,
|
|
OauthButton,
|
|
ParameterInputFull,
|
|
GoogleAuthButton,
|
|
},
|
|
props: {
|
|
credentialType: {
|
|
type: Object,
|
|
},
|
|
credentialProperties: {
|
|
type: Array,
|
|
},
|
|
parentTypes: {
|
|
type: Array,
|
|
},
|
|
credentialData: {},
|
|
credentialId: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
showValidationWarning: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
authError: {
|
|
type: String,
|
|
},
|
|
testedSuccessfully: {
|
|
type: Boolean,
|
|
},
|
|
isOAuthType: {
|
|
type: Boolean,
|
|
},
|
|
isOAuthConnected: {
|
|
type: Boolean,
|
|
},
|
|
isRetesting: {
|
|
type: Boolean,
|
|
},
|
|
credentialPermissions: {
|
|
type: Object,
|
|
default: (): IPermissions => ({}),
|
|
},
|
|
requiredPropertiesFilled: {
|
|
type: Boolean,
|
|
},
|
|
mode: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
showAuthTypeSelector: {
|
|
type: Boolean,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
EnterpriseEditionFeature,
|
|
};
|
|
},
|
|
async beforeMount() {
|
|
if (this.rootStore.defaultLocale === 'en') return;
|
|
|
|
this.uiStore.activeCredentialType = this.credentialType.name;
|
|
|
|
const key = `n8n-nodes-base.credentials.${this.credentialType.name}`;
|
|
|
|
if (this.$locale.exists(key)) return;
|
|
|
|
const credTranslation = await this.restApi().getCredentialTranslation(this.credentialType.name);
|
|
|
|
addCredentialTranslation(
|
|
{ [this.credentialType.name]: credTranslation },
|
|
this.rootStore.defaultLocale,
|
|
);
|
|
},
|
|
computed: {
|
|
...mapStores(
|
|
useCredentialsStore,
|
|
useNDVStore,
|
|
useNodeTypesStore,
|
|
useRootStore,
|
|
useUIStore,
|
|
useWorkflowsStore,
|
|
),
|
|
activeNodeType(): INodeTypeDescription | null {
|
|
const activeNode = this.ndvStore.activeNode;
|
|
|
|
if (activeNode) {
|
|
return this.nodeTypesStore.getNodeType(activeNode.type, activeNode.typeVersion);
|
|
}
|
|
return null;
|
|
},
|
|
appName(): string {
|
|
if (!this.credentialType) {
|
|
return '';
|
|
}
|
|
|
|
const appName = getAppNameFromCredType((this.credentialType as ICredentialType).displayName);
|
|
|
|
return (
|
|
appName ||
|
|
this.$locale.baseText('credentialEdit.credentialConfig.theServiceYouReConnectingTo')
|
|
);
|
|
},
|
|
credentialTypeName(): string {
|
|
return (this.credentialType as ICredentialType).name;
|
|
},
|
|
credentialOwnerName(): string {
|
|
return this.credentialsStore.getCredentialOwnerName(`${this.credentialId}`);
|
|
},
|
|
documentationUrl(): string {
|
|
const type = this.credentialType as ICredentialType;
|
|
const activeNode = this.ndvStore.activeNode;
|
|
const isCommunityNode = activeNode ? isCommunityPackageName(activeNode.type) : false;
|
|
|
|
const documentationUrl = type && type.documentationUrl;
|
|
|
|
if (!documentationUrl) {
|
|
return '';
|
|
}
|
|
|
|
let url: URL;
|
|
if (documentationUrl.startsWith('https://') || documentationUrl.startsWith('http://')) {
|
|
url = new URL(documentationUrl);
|
|
if (url.hostname !== DOCS_DOMAIN) return documentationUrl;
|
|
} else {
|
|
// Don't show documentation link for community nodes if the URL is not an absolute path
|
|
if (isCommunityNode) return '';
|
|
else url = new URL(`${BUILTIN_CREDENTIALS_DOCS_URL}${documentationUrl}/`);
|
|
}
|
|
|
|
if (url.hostname === DOCS_DOMAIN) {
|
|
url.searchParams.set('utm_source', 'n8n_app');
|
|
url.searchParams.set('utm_medium', 'left_nav_menu');
|
|
url.searchParams.set('utm_campaign', 'create_new_credentials_modal');
|
|
}
|
|
|
|
return url.href;
|
|
},
|
|
isGoogleOAuthType(): boolean {
|
|
return (
|
|
this.credentialTypeName === 'googleOAuth2Api' ||
|
|
this.parentTypes.includes('googleOAuth2Api')
|
|
);
|
|
},
|
|
oAuthCallbackUrl(): string {
|
|
const oauthType =
|
|
this.credentialTypeName === 'oAuth2Api' || this.parentTypes.includes('oAuth2Api')
|
|
? 'oauth2'
|
|
: 'oauth1';
|
|
return this.rootStore.oauthCallbackUrls[oauthType as keyof {}];
|
|
},
|
|
showOAuthSuccessBanner(): boolean {
|
|
return (
|
|
this.isOAuthType &&
|
|
this.requiredPropertiesFilled &&
|
|
this.isOAuthConnected &&
|
|
!this.authError
|
|
);
|
|
},
|
|
isMissingCredentials(): boolean {
|
|
return this.credentialType === null;
|
|
},
|
|
isNewCredential(): boolean {
|
|
return this.mode === 'new' && !this.credentialId;
|
|
},
|
|
},
|
|
methods: {
|
|
getCredentialOptions(type: string): ICredentialsResponse[] {
|
|
return this.credentialsStore.allUsableCredentialsByType[type];
|
|
},
|
|
onDataChange(event: { name: string; value: string | number | boolean | Date | null }): void {
|
|
this.$emit('change', event);
|
|
},
|
|
onDocumentationUrlClick(): void {
|
|
this.$telemetry.track('User clicked credential modal docs link', {
|
|
docs_link: this.documentationUrl,
|
|
credential_type: this.credentialTypeName,
|
|
source: 'modal',
|
|
workflow_id: this.workflowsStore.workflowId,
|
|
});
|
|
},
|
|
onAuthTypeChange(newType: string): void {
|
|
this.$emit('authTypeChanged', newType);
|
|
},
|
|
},
|
|
watch: {
|
|
showOAuthSuccessBanner(newValue, oldValue) {
|
|
if (newValue && !oldValue) {
|
|
this.$emit('scrollToTop');
|
|
}
|
|
},
|
|
},
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" module>
|
|
.container {
|
|
--notice-margin: 0;
|
|
> * {
|
|
margin-bottom: var(--spacing-l);
|
|
}
|
|
}
|
|
.googleReconnectLabel {
|
|
margin-right: var(--spacing-3xs);
|
|
}
|
|
</style>
|