fix: webapp sign in support new webapp_auth config

pull/18656/head
NFish 1 year ago
parent 7eb52770ad
commit fe01f3ac72

@ -3,6 +3,7 @@ import { useRouter, useSearchParams } from 'next/navigation'
import type { FC } from 'react'
import React, { useCallback, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { RiDoorLockLine } from '@remixicon/react'
import cn from '@/utils/classnames'
import Toast from '@/app/components/base/toast'
import { fetchWebOAuth2SSOUrl, fetchWebOIDCSSOUrl, fetchWebSAMLSSOUrl } from '@/service/share'
@ -98,18 +99,34 @@ const WebSSOForm: FC = () => {
init()
}, [message, processTokenAndRedirect, tokenFromUrl])
if (systemFeatures.webapp_auth.enable) {
return (
<div className="flex items-center justify-center h-full">
<div className={cn('flex flex-col items-center w-full grow justify-center', 'px-6', 'md:px-[108px]')}>
<Button variant='primary' onClick={() => { handleSSOLogin() }}>{t('login.withSSO')}</Button>
if (systemFeatures.webapp_auth.enabled) {
if (systemFeatures.webapp_auth.allow_sso) {
return (
<div className="flex items-center justify-center h-full">
<div className={cn('flex flex-col items-center w-full grow justify-center', 'px-6', 'md:px-[108px]')}>
<Button variant='primary' onClick={() => { handleSSOLogin() }}>{t('login.withSSO')}</Button>
</div>
</div>
)
}
return <div className="flex items-center justify-center h-full">
<div className="p-4 rounded-lg bg-gradient-to-r from-workflow-workflow-progress-bg-1 to-workflow-workflow-progress-bg-2">
<div className='flex items-center justify-center w-10 h-10 rounded-xl bg-components-card-bg shadow shadows-shadow-lg mb-2'>
<RiDoorLockLine className='w-5 h-5' />
</div>
<p className='system-sm-medium text-text-primary'>{t('login.webapp.noLoginMethod')}</p>
<p className='system-xs-regular text-text-tertiary mt-1'>{t('login.webapp.noLoginMethodTip')}</p>
</div>
)
<div className="relative my-2 py-2">
<div className="absolute inset-0 flex items-center" aria-hidden="true">
<div className='bg-gradient-to-r from-background-gradient-mask-transparent via-divider-regular to-background-gradient-mask-transparent h-px w-full'></div>
</div>
</div>
</div>
}
else {
return <div className="flex items-center justify-center h-full">
<p>Current App is not required for login, you can <span className='text-text-accent cursor-pointer' onClick={goWebApp}>click here</span> continue.</p>
<p className='system-xs-regular text-text-tertiary'>{t('login.webapp.disabled')}</p>
</div>
}
}

@ -35,7 +35,7 @@ export default function AccessControl(props: AccessControlProps) {
useEffect(() => {
setAppId(app.id)
setCurrentMenu(app.access_mode ?? AccessMode.SPECIFIC_GROUPS_MEMBERS)
}, [app, setAppId])
}, [app, setAppId, setCurrentMenu])
const { isPending, mutateAsync: updateAccessMode } = useUpdateAccessMode()
const handleConfirm = useCallback(async () => {

@ -20,7 +20,7 @@ export default function SpecificGroupsOrMembers() {
const setSpecificMembers = useAccessControlStore(s => s.setSpecificMembers)
const { t } = useTranslation()
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const hideTip = systemFeatures.webapp_auth.enable
const hideTip = systemFeatures.webapp_auth.enabled
const { isPending, data } = useAppWhiteListSubjects(appId, Boolean(appId) && currentMenu === AccessMode.SPECIFIC_GROUPS_MEMBERS)
useEffect(() => {

@ -104,6 +104,11 @@ const translation = {
licenseLostTip: 'Failed to connect Dify license server. Please contact your administrator to continue using Dify.',
licenseInactive: 'License Inactive',
licenseInactiveTip: 'The Dify Enterprise license for your workspace is inactive. Please contact your administrator to continue using Dify.',
webapp: {
noLoginMethod: 'Authentication method not configured for webapp',
noLoginMethodTip: 'Please contact the system admin to add an authentication method.',
disabled: 'Webapp authentication is disabled. Please contact the system admin to enable it. You can try to use the app directly.',
},
}
export default translation

@ -105,6 +105,11 @@ const translation = {
licenseInactiveTip: 'ワークスペースの Dify Enterprise ライセンスが非アクティブです。Difyを引き続き使用するには、管理者に連絡してください。',
licenseExpired: 'ライセンスの有効期限が切れています',
licenseLostTip: 'Difyライセンスサーバーへの接続に失敗しました。続けてDifyを使用するために管理者に連絡してください。',
webapp: {
noLoginMethod: 'Webアプリに対して認証方法が構成されていません',
noLoginMethodTip: 'システム管理者に連絡して、認証方法を追加してください。',
disabled: 'Webアプリの認証が無効になっています。システム管理者に連絡して有効にしてください。直接アプリを使用してみてください。',
},
}
export default translation

@ -105,6 +105,11 @@ const translation = {
licenseLostTip: '无法连接 Dify 许可证服务器,请联系管理员以继续使用 Dify。',
licenseInactive: '许可证未激活',
licenseInactiveTip: '您所在空间的 Dify Enterprise 许可证尚未激活,请联系管理员以继续使用 Dify。',
webapp: {
noLoginMethod: 'Web 应用未配置身份认证方式',
noLoginMethodTip: '请联系系统管理员添加身份认证方式',
disabled: 'Web 应用身份认证已禁用,请联系系统管理员启用。您也可以尝试直接使用应用。',
},
}
export default translation

@ -36,7 +36,7 @@ export type SystemFeatures = {
application_title: string
}
webapp_auth: {
enable: boolean
enabled: boolean
allow_sso: boolean
sso_config: {
protocol: SSOProtocol
@ -65,7 +65,7 @@ export const defaultSystemFeatures: SystemFeatures = {
application_title: 'test title',
},
webapp_auth: {
enable: false,
enabled: false,
allow_sso: false,
sso_config: {
protocol: SSOProtocol.SAML,

Loading…
Cancel
Save