Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,7 @@
"oauthSuccess": "Authorized — save the connection",
"oauthFailed": "Failed to fetch OAuth result",
"oauthStartFailed": "Could not start OAuth",
"oauthPopupBlocked": "The authorization window was blocked. Allow pop-ups for this site and try again.",
"oauthCompleteHint": "Enter a display name and save",
"chatPicker": "Connectors",
"chatPickerSearch": "Search connectors",
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -3062,6 +3062,7 @@
"oauthSuccess": "授权成功,请保存连接",
"oauthFailed": "获取授权结果失败",
"oauthStartFailed": "无法启动 OAuth",
"oauthPopupBlocked": "授权窗口被浏览器拦截,请允许本站弹出窗口后重试",
"oauthCompleteHint": "请填写显示名称并保存连接",
"chatPicker": "连接器",
"chatPickerSearch": "搜索连接器",
Expand Down
28 changes: 21 additions & 7 deletions dashboard/src/pages/Agent/Connectors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function ConnectorConfigDrawer({
const [form] = Form.useForm();
const [saving, setSaving] = useState(false);
const [probing, setProbing] = useState(false);
const [authorizing, setAuthorizing] = useState(false);
const [showManual, setShowManual] = useState(false);
const [authInfo, setAuthInfo] = useState<ConnectorAuthInfo | null>(null);
const [instanceDetail, setInstanceDetail] =
Expand Down Expand Up @@ -313,22 +314,30 @@ function ConnectorConfigDrawer({
};

const handleOAuth = async () => {
if (!entry) return;
if (!entry || authorizing) return;
const popup = window.open("", "octop-oauth", "width=520,height=720");
if (!popup) {
message.error(
t(
"connectors.oauthPopupBlocked",
"授权窗口被浏览器拦截,请允许本站弹出窗口后重试",
),
);
return;
}

setAuthorizing(true);
try {
const { authorize_url, state_id } = await connectorsApi.oauthStart(
entry.kind,
"/connectors",
);
const popup = window.open(
authorize_url,
"octop-oauth",
"width=520,height=720",
);
const onMessage = async (ev: MessageEvent) => {
if (ev.origin !== window.location.origin) return;
if (ev.data?.type !== "octop:connector-oauth") return;
if (ev.data.state_id !== state_id) return;
window.removeEventListener("message", onMessage);
popup?.close();
popup.close();
try {
const pending = await connectorsApi.oauthPending(state_id);
const tokens = pending.tokens ?? {};
Expand All @@ -347,11 +356,15 @@ function ConnectorConfigDrawer({
}
};
window.addEventListener("message", onMessage);
popup.location.replace(authorize_url);
} catch (e) {
popup.close();
console.error(e);
message.error(
apiErrorMessage(e, t("connectors.oauthStartFailed", "无法启动 OAuth")),
);
} finally {
setAuthorizing(false);
}
};

Expand Down Expand Up @@ -520,6 +533,7 @@ function ConnectorConfigDrawer({
<Button
type="primary"
icon={<Sparkles size={14} />}
loading={authorizing}
onClick={() => void handleOAuth()}
>
{t("connectors.oneClickOAuth", "一键授权")}
Expand Down
Loading