mirror of
https://github.com/langgenius/dify.git
synced 2026-11-29 16:18:01 +08:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
export type AuthorizationTab = 'workspace-auth' | 'app-user-auth' | 'reuse-from-node'
|
|
|
|
export type OAuthClientDraft = { type: 'default' | 'custom' }
|
|
|
|
export type AppUserAuthDraft = {
|
|
oauthEnabled: boolean
|
|
apiKeyEnabled: boolean
|
|
description: string
|
|
client?: OAuthClientDraft
|
|
testCredentialId?: string | null
|
|
}
|
|
|
|
export type AppUserAuthErrors = {
|
|
methods: boolean
|
|
oauthClient: boolean
|
|
description: boolean
|
|
}
|
|
|
|
export const createAppUserAuthDraft = ({
|
|
canOAuth = true,
|
|
canApiKey = true,
|
|
defaultClientAvailable = false,
|
|
}: {
|
|
canOAuth?: boolean
|
|
canApiKey?: boolean
|
|
defaultClientAvailable?: boolean
|
|
} = {}): AppUserAuthDraft => ({
|
|
oauthEnabled: canOAuth,
|
|
apiKeyEnabled: canApiKey,
|
|
description: '',
|
|
client: defaultClientAvailable ? { type: 'default' } : undefined,
|
|
})
|
|
|
|
export const validateAppUserAuth = (draft: AppUserAuthDraft): AppUserAuthErrors => ({
|
|
methods: !draft.oauthEnabled && !draft.apiKeyEnabled,
|
|
oauthClient: draft.oauthEnabled && !draft.client,
|
|
description: !draft.description.trim() || draft.description.length > 50,
|
|
})
|