2023-04-04 05:28:29 -07:00
|
|
|
<script lang="ts" setup>
|
2023-05-23 06:25:28 -07:00
|
|
|
import { computed, ref, onMounted } from 'vue';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useSSOStore } from '@/stores/sso.store';
|
|
|
|
import { useUIStore } from '@/stores/ui.store';
|
2023-04-04 05:28:29 -07:00
|
|
|
import CopyInput from '@/components/CopyInput.vue';
|
2023-05-23 06:25:28 -07:00
|
|
|
import { useI18n, useMessage, useToast } from '@/composables';
|
2023-04-04 05:28:29 -07:00
|
|
|
|
2023-05-23 06:25:28 -07:00
|
|
|
const IdentityProviderSettingsType = {
|
|
|
|
URL: 'url',
|
|
|
|
XML: 'xml',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { i18n } = useI18n();
|
2023-04-04 05:28:29 -07:00
|
|
|
const ssoStore = useSSOStore();
|
2023-04-07 04:29:22 -07:00
|
|
|
const uiStore = useUIStore();
|
2023-05-23 06:25:28 -07:00
|
|
|
const message = useMessage();
|
|
|
|
const toast = useToast();
|
2023-04-04 05:28:29 -07:00
|
|
|
|
|
|
|
const ssoActivatedLabel = computed(() =>
|
|
|
|
ssoStore.isSamlLoginEnabled
|
2023-05-23 06:25:28 -07:00
|
|
|
? i18n.baseText('settings.sso.activated')
|
|
|
|
: i18n.baseText('settings.sso.deactivated'),
|
2023-04-04 05:28:29 -07:00
|
|
|
);
|
|
|
|
const ssoSettingsSaved = ref(false);
|
2023-05-23 06:25:28 -07:00
|
|
|
|
2023-04-04 05:28:29 -07:00
|
|
|
const redirectUrl = ref();
|
|
|
|
const entityId = ref();
|
|
|
|
|
2023-05-23 06:25:28 -07:00
|
|
|
const ipsOptions = ref([
|
|
|
|
{
|
|
|
|
label: i18n.baseText('settings.sso.settings.ips.options.url'),
|
|
|
|
value: IdentityProviderSettingsType.URL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: i18n.baseText('settings.sso.settings.ips.options.xml'),
|
|
|
|
value: IdentityProviderSettingsType.XML,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const ipsType = ref(IdentityProviderSettingsType.URL);
|
|
|
|
|
|
|
|
const metadataUrl = ref();
|
|
|
|
const metadata = ref();
|
|
|
|
|
|
|
|
const isSaveEnabled = computed(() => {
|
|
|
|
if (ipsType.value === IdentityProviderSettingsType.URL) {
|
|
|
|
return !!metadataUrl.value && metadataUrl.value !== ssoStore.samlConfig?.metadataUrl;
|
|
|
|
} else if (ipsType.value === IdentityProviderSettingsType.XML) {
|
|
|
|
return !!metadata.value && metadata.value !== ssoStore.samlConfig?.metadata;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
const isTestEnabled = computed(() => {
|
|
|
|
if (ipsType.value === IdentityProviderSettingsType.URL) {
|
|
|
|
return !!metadataUrl.value && ssoSettingsSaved.value;
|
|
|
|
} else if (ipsType.value === IdentityProviderSettingsType.XML) {
|
|
|
|
return !!metadata.value && ssoSettingsSaved.value;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2023-04-04 05:28:29 -07:00
|
|
|
const getSamlConfig = async () => {
|
|
|
|
const config = await ssoStore.getSamlConfig();
|
2023-05-23 06:25:28 -07:00
|
|
|
|
2023-04-04 05:28:29 -07:00
|
|
|
entityId.value = config?.entityID;
|
|
|
|
redirectUrl.value = config?.returnUrl;
|
2023-05-23 06:25:28 -07:00
|
|
|
|
|
|
|
if (config?.metadataUrl) {
|
|
|
|
ipsType.value = IdentityProviderSettingsType.URL;
|
|
|
|
} else if (config?.metadata) {
|
|
|
|
ipsType.value = IdentityProviderSettingsType.XML;
|
|
|
|
}
|
|
|
|
|
2023-04-04 05:28:29 -07:00
|
|
|
metadata.value = config?.metadata;
|
2023-05-23 06:25:28 -07:00
|
|
|
metadataUrl.value = config?.metadataUrl;
|
2023-04-04 05:28:29 -07:00
|
|
|
ssoSettingsSaved.value = !!config?.metadata;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onSave = async () => {
|
|
|
|
try {
|
2023-05-23 06:25:28 -07:00
|
|
|
const config =
|
|
|
|
ipsType.value === IdentityProviderSettingsType.URL
|
|
|
|
? { metadataUrl: metadataUrl.value }
|
|
|
|
: { metadata: metadata.value };
|
|
|
|
await ssoStore.saveSamlConfig(config);
|
|
|
|
|
|
|
|
if (!ssoStore.isSamlLoginEnabled) {
|
|
|
|
const answer = await message.confirm(
|
|
|
|
i18n.baseText('settings.sso.settings.save.activate.message'),
|
|
|
|
i18n.baseText('settings.sso.settings.save.activate.title'),
|
|
|
|
{
|
|
|
|
confirmButtonText: i18n.baseText('settings.sso.settings.save.activate.test'),
|
|
|
|
cancelButtonText: i18n.baseText('settings.sso.settings.save.activate.cancel'),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (answer === 'confirm') {
|
|
|
|
await onTest();
|
|
|
|
}
|
|
|
|
}
|
2023-04-04 05:28:29 -07:00
|
|
|
} catch (error) {
|
2023-05-23 06:25:28 -07:00
|
|
|
toast.showError(error, i18n.baseText('settings.sso.settings.save.error'));
|
|
|
|
return;
|
|
|
|
} finally {
|
|
|
|
await getSamlConfig();
|
2023-04-04 05:28:29 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const onTest = async () => {
|
|
|
|
try {
|
|
|
|
const url = await ssoStore.testSamlConfig();
|
2023-05-23 06:25:28 -07:00
|
|
|
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.open(url, '_blank');
|
|
|
|
}
|
2023-04-04 05:28:29 -07:00
|
|
|
} catch (error) {
|
2023-05-23 06:25:28 -07:00
|
|
|
toast.showError(error, 'error');
|
2023-04-04 05:28:29 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-07 04:29:22 -07:00
|
|
|
const goToUpgrade = () => {
|
2023-04-20 04:25:57 -07:00
|
|
|
uiStore.goToUpgrade('sso', 'upgrade-sso');
|
2023-04-07 04:29:22 -07:00
|
|
|
};
|
|
|
|
|
2023-05-23 06:25:28 -07:00
|
|
|
onMounted(async () => {
|
2023-04-07 04:29:22 -07:00
|
|
|
if (!ssoStore.isEnterpriseSamlEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2023-04-04 05:28:29 -07:00
|
|
|
try {
|
|
|
|
await getSamlConfig();
|
|
|
|
} catch (error) {
|
2023-05-23 06:25:28 -07:00
|
|
|
toast.showError(error, 'error');
|
2023-04-04 05:28:29 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2023-05-23 06:25:28 -07:00
|
|
|
<n8n-heading size="2xlarge">{{ i18n.baseText('settings.sso.title') }}</n8n-heading>
|
2023-04-04 05:28:29 -07:00
|
|
|
<div :class="$style.top">
|
2023-05-23 06:25:28 -07:00
|
|
|
<n8n-heading size="xlarge">{{ i18n.baseText('settings.sso.subtitle') }}</n8n-heading>
|
|
|
|
<n8n-tooltip
|
|
|
|
v-if="ssoStore.isEnterpriseSamlEnabled"
|
|
|
|
:disabled="ssoStore.isSamlLoginEnabled || ssoSettingsSaved"
|
|
|
|
>
|
2023-04-04 05:28:29 -07:00
|
|
|
<template #content>
|
|
|
|
<span>
|
2023-05-23 06:25:28 -07:00
|
|
|
{{ i18n.baseText('settings.sso.activation.tooltip') }}
|
2023-04-04 05:28:29 -07:00
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<el-switch
|
|
|
|
v-model="ssoStore.isSamlLoginEnabled"
|
|
|
|
:disabled="!ssoSettingsSaved"
|
|
|
|
:class="$style.switch"
|
|
|
|
:inactive-text="ssoActivatedLabel"
|
|
|
|
/>
|
|
|
|
</n8n-tooltip>
|
|
|
|
</div>
|
|
|
|
<n8n-info-tip>
|
2023-05-23 06:25:28 -07:00
|
|
|
{{ i18n.baseText('settings.sso.info') }}
|
|
|
|
<a href="https://docs.n8n.io/user-management/saml/" target="_blank">
|
|
|
|
{{ i18n.baseText('settings.sso.info.link') }}
|
|
|
|
</a>
|
2023-04-04 05:28:29 -07:00
|
|
|
</n8n-info-tip>
|
2023-04-14 04:17:20 -07:00
|
|
|
<div v-if="ssoStore.isEnterpriseSamlEnabled" data-test-id="sso-content-licensed">
|
2023-04-07 04:29:22 -07:00
|
|
|
<div :class="$style.group">
|
2023-05-23 06:25:28 -07:00
|
|
|
<label>{{ i18n.baseText('settings.sso.settings.redirectUrl.label') }}</label>
|
2023-04-07 04:29:22 -07:00
|
|
|
<CopyInput
|
|
|
|
:value="redirectUrl"
|
2023-05-23 06:25:28 -07:00
|
|
|
:copy-button-text="i18n.baseText('generic.clickToCopy')"
|
|
|
|
:toast-title="i18n.baseText('settings.sso.settings.redirectUrl.copied')"
|
2023-04-07 04:29:22 -07:00
|
|
|
/>
|
2023-05-23 06:25:28 -07:00
|
|
|
<small>{{ i18n.baseText('settings.sso.settings.redirectUrl.help') }}</small>
|
2023-04-07 04:29:22 -07:00
|
|
|
</div>
|
|
|
|
<div :class="$style.group">
|
2023-05-23 06:25:28 -07:00
|
|
|
<label>{{ i18n.baseText('settings.sso.settings.entityId.label') }}</label>
|
2023-04-07 04:29:22 -07:00
|
|
|
<CopyInput
|
|
|
|
:value="entityId"
|
2023-05-23 06:25:28 -07:00
|
|
|
:copy-button-text="i18n.baseText('generic.clickToCopy')"
|
|
|
|
:toast-title="i18n.baseText('settings.sso.settings.entityId.copied')"
|
2023-04-07 04:29:22 -07:00
|
|
|
/>
|
2023-05-23 06:25:28 -07:00
|
|
|
<small>{{ i18n.baseText('settings.sso.settings.entityId.help') }}</small>
|
2023-04-07 04:29:22 -07:00
|
|
|
</div>
|
|
|
|
<div :class="$style.group">
|
2023-05-23 06:25:28 -07:00
|
|
|
<label>{{ i18n.baseText('settings.sso.settings.ips.label') }}</label>
|
|
|
|
<div class="mt-2xs mb-s">
|
|
|
|
<n8n-radio-buttons :options="ipsOptions" v-model="ipsType" />
|
|
|
|
</div>
|
|
|
|
<div v-show="ipsType === IdentityProviderSettingsType.URL">
|
|
|
|
<n8n-input
|
|
|
|
v-model="metadataUrl"
|
|
|
|
type="text"
|
|
|
|
name="metadataUrl"
|
|
|
|
size="large"
|
|
|
|
:placeholder="i18n.baseText('settings.sso.settings.ips.url.placeholder')"
|
|
|
|
/>
|
|
|
|
<small>{{ i18n.baseText('settings.sso.settings.ips.url.help') }}</small>
|
|
|
|
</div>
|
|
|
|
<div v-show="ipsType === IdentityProviderSettingsType.XML">
|
|
|
|
<n8n-input v-model="metadata" type="textarea" name="metadata" :rows="4" />
|
|
|
|
<small>{{ i18n.baseText('settings.sso.settings.ips.xml.help') }}</small>
|
|
|
|
</div>
|
2023-04-07 04:29:22 -07:00
|
|
|
</div>
|
|
|
|
<div :class="$style.buttons">
|
2023-05-23 06:25:28 -07:00
|
|
|
<n8n-button :disabled="!isSaveEnabled" @click="onSave" data-test-id="sso-save">
|
|
|
|
{{ i18n.baseText('settings.sso.settings.save') }}
|
|
|
|
</n8n-button>
|
2023-04-13 07:17:47 -07:00
|
|
|
<n8n-button
|
2023-05-23 06:25:28 -07:00
|
|
|
:disabled="!isTestEnabled"
|
2023-04-13 07:17:47 -07:00
|
|
|
type="tertiary"
|
|
|
|
@click="onTest"
|
2023-04-14 04:17:20 -07:00
|
|
|
data-test-id="sso-test"
|
2023-04-13 07:17:47 -07:00
|
|
|
>
|
2023-05-23 06:25:28 -07:00
|
|
|
{{ i18n.baseText('settings.sso.settings.test') }}
|
2023-04-07 04:29:22 -07:00
|
|
|
</n8n-button>
|
|
|
|
</div>
|
2023-05-23 06:25:28 -07:00
|
|
|
<footer :class="$style.footer">
|
|
|
|
{{ i18n.baseText('settings.sso.settings.footer.hint') }}
|
|
|
|
</footer>
|
2023-04-04 05:28:29 -07:00
|
|
|
</div>
|
2023-04-07 04:29:22 -07:00
|
|
|
<n8n-action-box
|
|
|
|
v-else
|
2023-04-14 04:17:20 -07:00
|
|
|
data-test-id="sso-content-unlicensed"
|
2023-04-07 04:29:22 -07:00
|
|
|
:class="$style.actionBox"
|
2023-05-23 06:25:28 -07:00
|
|
|
:description="i18n.baseText('settings.sso.actionBox.description')"
|
|
|
|
:buttonText="i18n.baseText('settings.sso.actionBox.buttonText')"
|
2023-04-07 04:29:22 -07:00
|
|
|
@click="goToUpgrade"
|
|
|
|
>
|
|
|
|
<template #heading>
|
2023-05-23 06:25:28 -07:00
|
|
|
<span>{{ i18n.baseText('settings.sso.actionBox.title') }}</span>
|
2023-04-07 04:29:22 -07:00
|
|
|
</template>
|
|
|
|
</n8n-action-box>
|
2023-04-04 05:28:29 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.top {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: var(--spacing-2xl) 0 var(--spacing-xl);
|
|
|
|
}
|
|
|
|
|
|
|
|
.switch {
|
|
|
|
span {
|
|
|
|
font-size: var(--font-size-2xs);
|
|
|
|
font-weight: var(--font-weight-bold);
|
|
|
|
color: var(--color-text-light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.buttons {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-start;
|
2023-05-23 06:25:28 -07:00
|
|
|
padding: var(--spacing-2xl) 0 var(--spacing-2xs);
|
2023-04-04 05:28:29 -07:00
|
|
|
|
|
|
|
button {
|
|
|
|
margin: 0 var(--spacing-s) 0 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.group {
|
|
|
|
padding: var(--spacing-xl) 0 0;
|
|
|
|
|
2023-05-23 06:25:28 -07:00
|
|
|
> label {
|
2023-04-04 05:28:29 -07:00
|
|
|
display: inline-block;
|
|
|
|
font-size: var(--font-size-s);
|
|
|
|
font-weight: var(--font-weight-bold);
|
|
|
|
padding: 0 0 var(--spacing-2xs);
|
|
|
|
}
|
|
|
|
|
|
|
|
small {
|
|
|
|
display: block;
|
|
|
|
padding: var(--spacing-2xs) 0 0;
|
|
|
|
font-size: var(--font-size-2xs);
|
|
|
|
color: var(--color-text-base);
|
|
|
|
}
|
|
|
|
}
|
2023-04-07 04:29:22 -07:00
|
|
|
|
|
|
|
.actionBox {
|
|
|
|
margin: var(--spacing-2xl) 0 0;
|
|
|
|
}
|
2023-05-23 06:25:28 -07:00
|
|
|
|
|
|
|
.footer {
|
|
|
|
color: var(--color-text-base);
|
|
|
|
font-size: var(--font-size-2xs);
|
|
|
|
}
|
2023-04-04 05:28:29 -07:00
|
|
|
</style>
|