tool oauth
parent
bda76080a9
commit
bdf5af7a6f
@ -0,0 +1,53 @@
|
|||||||
|
import {
|
||||||
|
useAddPluginCredential,
|
||||||
|
useDeletePluginCredential,
|
||||||
|
useGetPluginCredentialInfo,
|
||||||
|
useGetPluginCredentialSchema,
|
||||||
|
useInvalidPluginCredentialInfo,
|
||||||
|
useSetPluginDefaultCredential,
|
||||||
|
useUpdatePluginCredential,
|
||||||
|
} from '@/service/use-plugins-auth'
|
||||||
|
import { useGetApi } from './use-get-api'
|
||||||
|
import type { PluginPayload } from '../types'
|
||||||
|
import type { CredentialTypeEnum } from '../types'
|
||||||
|
|
||||||
|
export const useGetPluginCredentialInfoHook = (pluginPayload: PluginPayload, enable?: boolean) => {
|
||||||
|
const apiMap = useGetApi(pluginPayload)
|
||||||
|
return useGetPluginCredentialInfo(enable ? apiMap.getCredentialInfo : '')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useDeletePluginCredentialHook = (pluginPayload: PluginPayload) => {
|
||||||
|
const apiMap = useGetApi(pluginPayload)
|
||||||
|
|
||||||
|
return useDeletePluginCredential(apiMap.deleteCredential)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useInvalidPluginCredentialInfoHook = (pluginPayload: PluginPayload) => {
|
||||||
|
const apiMap = useGetApi(pluginPayload)
|
||||||
|
|
||||||
|
return useInvalidPluginCredentialInfo(apiMap.getCredentialInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSetPluginDefaultCredentialHook = (pluginPayload: PluginPayload) => {
|
||||||
|
const apiMap = useGetApi(pluginPayload)
|
||||||
|
|
||||||
|
return useSetPluginDefaultCredential(apiMap.setDefaultCredential)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useGetPluginCredentialSchemaHook = (pluginPayload: PluginPayload, credentialType: CredentialTypeEnum) => {
|
||||||
|
const apiMap = useGetApi(pluginPayload)
|
||||||
|
|
||||||
|
return useGetPluginCredentialSchema(apiMap.getCredentialSchema(credentialType))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAddPluginCredentialHook = (pluginPayload: PluginPayload) => {
|
||||||
|
const apiMap = useGetApi(pluginPayload)
|
||||||
|
|
||||||
|
return useAddPluginCredential(apiMap.addCredential)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useUpdatePluginCredentialHook = (pluginPayload: PluginPayload) => {
|
||||||
|
const apiMap = useGetApi(pluginPayload)
|
||||||
|
|
||||||
|
return useUpdatePluginCredential(apiMap.updateCredential)
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
import {
|
||||||
|
AuthCategory,
|
||||||
|
} from '../types'
|
||||||
|
import type {
|
||||||
|
CredentialTypeEnum,
|
||||||
|
PluginPayload,
|
||||||
|
} from '../types'
|
||||||
|
|
||||||
|
export const useGetApi = ({ category = AuthCategory.tool, provider }: PluginPayload) => {
|
||||||
|
if (category === AuthCategory.tool) {
|
||||||
|
return {
|
||||||
|
getCredentialInfo: `/workspaces/current/tool-provider/builtin/${provider}/credential/info`,
|
||||||
|
setDefaultCredential: `/workspaces/current/tool-provider/builtin/${provider}/default-credential`,
|
||||||
|
getCredentials: `/workspaces/current/tool-provider/builtin/${provider}/credentials`,
|
||||||
|
addCredential: `/workspaces/current/tool-provider/builtin/${provider}/add`,
|
||||||
|
updateCredential: `/workspaces/current/tool-provider/builtin/${provider}/update`,
|
||||||
|
deleteCredential: `/workspaces/current/tool-provider/builtin/${provider}/delete`,
|
||||||
|
getCredentialSchema: (credential_type: CredentialTypeEnum) => `/workspaces/current/tool-provider/builtin/${provider}/credential/schema/${credential_type}`,
|
||||||
|
getOauthUrl: `/oauth/plugin/${provider}/tool/authorization-url`,
|
||||||
|
getOauthClientSchema: `/workspaces/current/tool-provider/builtin/${provider}/oauth/client-schema`,
|
||||||
|
setCustomOauthClient: `/workspaces/current/tool-provider/builtin/${provider}/oauth/custom-client`,
|
||||||
|
getCustomOAuthClient: `/workspaces/current/tool-provider/builtin/${provider}/oauth/custom-client`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getCredentialInfo: '',
|
||||||
|
setDefaultCredential: '',
|
||||||
|
getCredentials: '',
|
||||||
|
addCredential: '',
|
||||||
|
updateCredential: '',
|
||||||
|
deleteCredential: '',
|
||||||
|
getCredentialSchema: () => '',
|
||||||
|
getOauthUrl: '',
|
||||||
|
getOauthClientSchema: '',
|
||||||
|
setCustomOauthClient: '',
|
||||||
|
getCustomOAuthClient: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
export { default as PluginAuth } from './plugin-auth'
|
export { default as PluginAuth } from './plugin-auth'
|
||||||
export { default as Authorized } from './authorized'
|
export { default as Authorized } from './authorized'
|
||||||
export { default as AuthorizedInNode } from './authorized-in-node'
|
export { default as AuthorizedInNode } from './authorized-in-node'
|
||||||
export { usePluginAuth } from './hooks'
|
export { usePluginAuth } from './hooks/use-plugin-auth'
|
||||||
|
export * from './types'
|
||||||
|
|||||||
Loading…
Reference in New Issue