mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 20:17:29 +08:00
fix(trigger): oauth client config
This commit is contained in:
parent
84c09ec59d
commit
fe4b63210e
@ -100,7 +100,7 @@ export const CreateSubscriptionButton = ({ buttonType = CreateButtonType.FULL_BU
|
|||||||
]
|
]
|
||||||
}, [t, oauthConfig, supportedMethods, methodType])
|
}, [t, oauthConfig, supportedMethods, methodType])
|
||||||
|
|
||||||
const onChooseCreateType = (type: SupportedCreationMethods) => {
|
const onChooseCreateType = async (type: SupportedCreationMethods) => {
|
||||||
if (type === SupportedCreationMethods.OAUTH) {
|
if (type === SupportedCreationMethods.OAUTH) {
|
||||||
if (oauthConfig?.configured) {
|
if (oauthConfig?.configured) {
|
||||||
initiateOAuth(detail?.provider || '', {
|
initiateOAuth(detail?.provider || '', {
|
||||||
@ -115,10 +115,10 @@ export const CreateSubscriptionButton = ({ buttonType = CreateButtonType.FULL_BU
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onError: (error: any) => {
|
onError: () => {
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: error?.message || t('pluginTrigger.modal.errors.authFailed'),
|
message: t('pluginTrigger.modal.oauth.authorization.authFailed'),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import Toast from '@/app/components/base/toast'
|
|||||||
import type { TriggerOAuthClientParams, TriggerOAuthConfig, TriggerSubscriptionBuilder } from '@/app/components/workflow/block-selector/types'
|
import type { TriggerOAuthClientParams, TriggerOAuthConfig, TriggerSubscriptionBuilder } from '@/app/components/workflow/block-selector/types'
|
||||||
import OptionCard from '@/app/components/workflow/nodes/_base/components/option-card'
|
import OptionCard from '@/app/components/workflow/nodes/_base/components/option-card'
|
||||||
import { openOAuthPopup } from '@/hooks/use-oauth'
|
import { openOAuthPopup } from '@/hooks/use-oauth'
|
||||||
|
import type { ConfigureTriggerOAuthPayload } from '@/service/use-triggers'
|
||||||
import {
|
import {
|
||||||
useConfigureTriggerOAuth,
|
useConfigureTriggerOAuth,
|
||||||
useDeleteTriggerOAuth,
|
useDeleteTriggerOAuth,
|
||||||
@ -71,10 +72,11 @@ export const OAuthClientSettingsModal = ({ oauthConfig, onClose, showOAuthCreate
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onError: (error: any) => {
|
onError: () => {
|
||||||
|
setAuthorizationStatus(AuthorizationStatusEnum.Failed)
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: error?.message || t('pluginTrigger.modal.errors.authFailed'),
|
message: t('pluginTrigger.modal.oauth.authorization.authFailed'),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -125,28 +127,32 @@ export const OAuthClientSettingsModal = ({ oauthConfig, onClose, showOAuthCreate
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleSave = (needAuth: boolean) => {
|
const handleSave = (needAuth: boolean) => {
|
||||||
const clientParams = clientFormRef.current?.getFormValues({})?.values || {}
|
const isCustom = clientType === ClientTypeEnum.Custom
|
||||||
if (clientParams.client_id === oauthConfig?.params.client_id)
|
const params: ConfigureTriggerOAuthPayload = {
|
||||||
clientParams.client_id = '[__HIDDEN__]'
|
|
||||||
|
|
||||||
if (clientParams.client_secret === oauthConfig?.params.client_secret)
|
|
||||||
clientParams.client_secret = '[__HIDDEN__]'
|
|
||||||
|
|
||||||
configureOAuth({
|
|
||||||
provider: providerName,
|
provider: providerName,
|
||||||
client_params: clientParams as TriggerOAuthClientParams,
|
enabled: isCustom,
|
||||||
enabled: clientType === ClientTypeEnum.Custom,
|
}
|
||||||
}, {
|
|
||||||
|
if (isCustom) {
|
||||||
|
const clientFormValues = clientFormRef.current?.getFormValues({}) as { values: TriggerOAuthClientParams, isCheckValidated: boolean }
|
||||||
|
if (!clientFormValues.isCheckValidated)
|
||||||
|
return
|
||||||
|
const clientParams = clientFormValues.values
|
||||||
|
if (clientParams.client_id === oauthConfig?.params.client_id)
|
||||||
|
clientParams.client_id = '[__HIDDEN__]'
|
||||||
|
|
||||||
|
if (clientParams.client_secret === oauthConfig?.params.client_secret)
|
||||||
|
clientParams.client_secret = '[__HIDDEN__]'
|
||||||
|
|
||||||
|
params.client_params = clientParams
|
||||||
|
}
|
||||||
|
|
||||||
|
configureOAuth(params, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
if (needAuth)
|
if (needAuth)
|
||||||
handleAuthorization()
|
handleAuthorization()
|
||||||
else
|
else
|
||||||
onClose()
|
onClose()
|
||||||
|
|
||||||
Toast.notify({
|
|
||||||
type: 'success',
|
|
||||||
message: t('pluginTrigger.modal.oauth.configuration.success'),
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
onError: (error: any) => {
|
onError: (error: any) => {
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
|
|||||||
@ -116,7 +116,7 @@ const translation = {
|
|||||||
authorizeButton: 'Authorize with {{provider}}',
|
authorizeButton: 'Authorize with {{provider}}',
|
||||||
waitingAuth: 'Waiting for authorization...',
|
waitingAuth: 'Waiting for authorization...',
|
||||||
authSuccess: 'Authorization successful',
|
authSuccess: 'Authorization successful',
|
||||||
authFailed: 'Authorization failed',
|
authFailed: 'Failed to get OAuth authorization information',
|
||||||
waitingJump: 'Authorized, waiting for jump',
|
waitingJump: 'Authorized, waiting for jump',
|
||||||
},
|
},
|
||||||
configuration: {
|
configuration: {
|
||||||
|
|||||||
@ -116,7 +116,7 @@ const translation = {
|
|||||||
authorizeButton: '使用 {{provider}} 授权',
|
authorizeButton: '使用 {{provider}} 授权',
|
||||||
waitingAuth: '等待授权中...',
|
waitingAuth: '等待授权中...',
|
||||||
authSuccess: '授权成功',
|
authSuccess: '授权成功',
|
||||||
authFailed: '授权失败',
|
authFailed: '获取 OAuth 授权信息失败',
|
||||||
waitingJump: '已授权,待跳转',
|
waitingJump: '已授权,待跳转',
|
||||||
},
|
},
|
||||||
configuration: {
|
configuration: {
|
||||||
|
|||||||
@ -233,14 +233,16 @@ export const useTriggerOAuthConfig = (provider: string, enabled = true) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ConfigureTriggerOAuthPayload = {
|
||||||
|
provider: string
|
||||||
|
client_params?: TriggerOAuthClientParams
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export const useConfigureTriggerOAuth = () => {
|
export const useConfigureTriggerOAuth = () => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: [NAME_SPACE, 'configure-oauth'],
|
mutationKey: [NAME_SPACE, 'configure-oauth'],
|
||||||
mutationFn: (payload: {
|
mutationFn: (payload: ConfigureTriggerOAuthPayload) => {
|
||||||
provider: string
|
|
||||||
client_params: TriggerOAuthClientParams
|
|
||||||
enabled: boolean
|
|
||||||
}) => {
|
|
||||||
const { provider, ...body } = payload
|
const { provider, ...body } = payload
|
||||||
return post<{ result: string }>(
|
return post<{ result: string }>(
|
||||||
`/workspaces/current/trigger-provider/${provider}/oauth/client`,
|
`/workspaces/current/trigger-provider/${provider}/oauth/client`,
|
||||||
@ -267,6 +269,8 @@ export const useInitiateTriggerOAuth = () => {
|
|||||||
mutationFn: (provider: string) => {
|
mutationFn: (provider: string) => {
|
||||||
return get<{ authorization_url: string; subscription_builder: TriggerSubscriptionBuilder }>(
|
return get<{ authorization_url: string; subscription_builder: TriggerSubscriptionBuilder }>(
|
||||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/oauth/authorize`,
|
`/workspaces/current/trigger-provider/${provider}/subscriptions/oauth/authorize`,
|
||||||
|
{},
|
||||||
|
{ silent: true },
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user