Файли
openidea/src/features/ssh/AskpassDialog.tsx
T
arookieofcтаa-rookie-of-C-language e85ffa2ae8 feat(git): remember HTTPS credentials in the app secret store (#321)
Git no longer asks for the HTTPS user name and password on every fetch, pull and push. The password prompt offers "Remember for this host"; the credential is saved in the app's secret store (next to the saved SSH passwords, never in git's global configuration) only after the git command that used it succeeds, and a stored credential the server rejects is forgotten so the next command asks again. Settings › Version Control › Git lists saved credentials and forgets them.

Each git child gets its own id, passed to the askpass helper, so concurrent commands never save or forget each other's credentials. ide-vcs reports command completion through an observer installed at start-up instead of depending on ide-ssh. Credentials are keyed by scheme, host and port, and only git's authentication errors (Authentication failed, HTTP 401/403 responses, invalid username or password) forget a stored credential.

Fixes #272

Co-authored-by: a-rookie-of-C-language <[email protected]>
2026-10-30 10:48:29 +08:00

72 рядки
2.2 KiB
TypeScript

/** The oldest pending askpass prompt as a modal: password / text field, or Yes / No for a host key. */
import { useState } from "react";
import { useTx } from "@/platform/i18n";
import { Checkbox, Dialog, Input } from "@/ui";
import { answerAskpass, askpassAnswer, useAskpass, type AskpassPrompt } from "./askpass";
import styles from "./Ssh.module.css";
export function AskpassHost() {
const head = useAskpass((s) => s.queue[0]);
return head ? <AskpassDialog key={head.id} prompt={head} /> : null;
}
function AskpassDialog({ prompt: p }: { prompt: AskpassPrompt }) {
const tx = useTx();
const [text, setText] = useState("");
const [remember, setRemember] = useState(true);
const done = (choice: Parameters<typeof askpassAnswer>[1]) =>
answerAskpass(p, askpassAnswer(p.kind, choice), remember);
const cancel = () => done(null);
if (p.kind === "confirm")
return (
<Dialog
open
icon="warning"
title={tx("SSH")}
onClose={cancel}
width={480}
buttons={[
{ label: "Yes", role: "default", onClick: () => done({ confirm: true }) },
{ label: "No", onClick: () => done({ confirm: false }) },
{ label: "Cancel", role: "cancel" },
]}
>
<div className={styles.prompt}>{p.prompt}</div>
</Dialog>
);
return (
<Dialog
open
title={tx(p.kind === "secret" ? "SSH Password" : "SSH")}
onClose={cancel}
width={440}
buttons={[
{ label: "OK", role: "default", onClick: () => done({ text }) },
{ label: "Cancel", role: "cancel" },
]}
>
<form
className={styles.form}
onSubmit={(e) => {
e.preventDefault();
done({ text });
}}
>
<label className={styles.prompt} htmlFor="askpass-input">
{p.prompt}
</label>
<Input
id="askpass-input"
data-autofocus
type={p.kind === "secret" ? "password" : "text"}
value={text}
onChange={(e) => setText(e.target.value)}
/>
{p.remember && <Checkbox checked={remember} onChange={setRemember} label={tx("Remember for this host")} />}
</form>
</Dialog>
);
}