mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 10:28:10 +08:00
support re-authorization
This commit is contained in:
@ -6,15 +6,13 @@ export const useOAuthCallback = () => {
|
||||
const searchParams = useSearchParams()
|
||||
|
||||
useEffect(() => {
|
||||
const code = searchParams.get('code')
|
||||
const state = searchParams.get('state')
|
||||
const MCPProviderID = searchParams.get('mcp_provider_id')
|
||||
|
||||
if (code && state && window.opener) {
|
||||
if (MCPProviderID && window.opener) {
|
||||
window.opener.postMessage({
|
||||
type: 'oauth_callback',
|
||||
payload: {
|
||||
code,
|
||||
state,
|
||||
state: MCPProviderID,
|
||||
},
|
||||
}, '*')
|
||||
window.close()
|
||||
@ -22,7 +20,7 @@ export const useOAuthCallback = () => {
|
||||
}, [searchParams])
|
||||
}
|
||||
|
||||
export const openOAuthPopup = (url: string, callback: (state: string, code: string) => void) => {
|
||||
export const openOAuthPopup = (url: string, callback: (state: string) => void) => {
|
||||
const width = 600
|
||||
const height = 600
|
||||
const left = window.screenX + (window.outerWidth - width) / 2
|
||||
@ -37,8 +35,8 @@ export const openOAuthPopup = (url: string, callback: (state: string, code: stri
|
||||
const handleMessage = (event: MessageEvent) => {
|
||||
if (event.data?.type === 'oauth_callback') {
|
||||
window.removeEventListener('message', handleMessage)
|
||||
const { code, state } = event.data.payload
|
||||
callback(state, code)
|
||||
const { state } = event.data.payload
|
||||
callback(state)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user