forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): SSO login button (n8n-io#5615)
* feat(editor): SSO login button * feat(editor): SSO login button * feat(editor): SSO login button
- Loading branch information
Showing
12 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
{{ redirectText }} | ||
</n8n-link> | ||
</div> | ||
<slot></slot> | ||
</div> | ||
</template> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { makeRestApiRequest } from '@/utils'; | ||
import { IRestApiContext } from '@/Interface'; | ||
|
||
export const initSSO = (context: IRestApiContext): Promise<string> => { | ||
return makeRestApiRequest(context, 'GET', '/sso/saml/initsso'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script lang="ts" setup> | ||
import { Notification } from 'element-ui'; | ||
import { useSSOStore } from '@/stores/sso'; | ||
const ssoStore = useSSOStore(); | ||
const onSSOLogin = async () => { | ||
try { | ||
window.location.href = await ssoStore.getSSORedirectUrl(); | ||
} catch (error) { | ||
Notification.error({ | ||
title: 'Error', | ||
message: error.message, | ||
position: 'bottom-right', | ||
}); | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div v-if="ssoStore.showSsoLoginButton" :class="$style.ssoLogin"> | ||
<div :class="$style.divider"> | ||
<span>{{ $locale.baseText('sso.login.divider') }}</span> | ||
</div> | ||
<n8n-button | ||
@click="onSSOLogin" | ||
size="large" | ||
type="primary" | ||
outline | ||
:label="$locale.baseText('sso.login.button')" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" module> | ||
.ssoLogin { | ||
text-align: center; | ||
} | ||
.divider { | ||
position: relative; | ||
text-transform: uppercase; | ||
&::before { | ||
content: ''; | ||
position: absolute; | ||
top: 50%; | ||
left: 0; | ||
width: 100%; | ||
height: 1px; | ||
background-color: var(--color-foreground-base); | ||
} | ||
span { | ||
position: relative; | ||
display: inline-block; | ||
padding: var(--spacing-xl) var(--spacing-l); | ||
background: var(--color-foreground-xlight); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { computed, reactive } from 'vue'; | ||
import { defineStore } from 'pinia'; | ||
import { EnterpriseEditionFeature } from '@/constants'; | ||
import { useRootStore } from '@/stores/n8nRootStore'; | ||
import { useSettingsStore } from '@/stores/settings'; | ||
import { initSSO } from '@/api/sso'; | ||
|
||
export const useSSOStore = defineStore('sso', () => { | ||
const rootStore = useRootStore(); | ||
const settingsStore = useSettingsStore(); | ||
|
||
const state = reactive({ | ||
loading: false, | ||
}); | ||
|
||
const isLoading = computed(() => state.loading); | ||
|
||
const setLoading = (loading: boolean) => { | ||
state.loading = loading; | ||
}; | ||
|
||
const isSamlLoginEnabled = computed(() => settingsStore.isSamlLoginEnabled); | ||
const isEnterpriseSamlEnabled = computed(() => | ||
settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.Saml), | ||
); | ||
const isDefaultAuthenticationSaml = computed(() => settingsStore.isDefaultAuthenticationSaml); | ||
const showSsoLoginButton = computed( | ||
() => | ||
isSamlLoginEnabled.value && | ||
isEnterpriseSamlEnabled.value && | ||
isDefaultAuthenticationSaml.value, | ||
); | ||
|
||
const getSSORedirectUrl = () => initSSO(rootStore.getRestApiContext); | ||
|
||
return { | ||
isLoading, | ||
setLoading, | ||
showSsoLoginButton, | ||
getSSORedirectUrl, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters