mirror of
https://github.com/desktop/desktop
synced 2024-10-02 14:23:59 +00:00
Don't request username if provided in url
This commit is contained in:
parent
185cf60af9
commit
eb85e8555c
|
@ -179,6 +179,7 @@ const handleAskPassUserPassword = async (
|
|||
const warn = (msg: string) => log.warn(`askPassHandler: ${msg}`)
|
||||
|
||||
const { trampolineToken } = command
|
||||
const parsedUrl = new URL(remoteUrl)
|
||||
const account = await findAccount(trampolineToken, accountsStore, remoteUrl)
|
||||
|
||||
if (!account) {
|
||||
|
@ -194,7 +195,7 @@ const handleAskPassUserPassword = async (
|
|||
|
||||
info(`no account found for ${remoteUrl}`)
|
||||
|
||||
if (new URL(remoteUrl).hostname === 'github.com') {
|
||||
if (parsedUrl.hostname === 'github.com') {
|
||||
// We don't want to show a generic auth prompt for GitHub.com and we
|
||||
// don't have a good way to turn the sign in flow into a promise. More
|
||||
// specifically we can create a promise that resolves when the GH sign in
|
||||
|
@ -204,7 +205,10 @@ const handleAskPassUserPassword = async (
|
|||
}
|
||||
|
||||
const { username, password } =
|
||||
await trampolineUIHelper.promptForGenericGitAuthentication(remoteUrl)
|
||||
await trampolineUIHelper.promptForGenericGitAuthentication(
|
||||
remoteUrl,
|
||||
parsedUrl.username === '' ? undefined : parsedUrl.username
|
||||
)
|
||||
|
||||
if (username.length > 0 && password.length > 0) {
|
||||
setGenericUsername(remoteUrl, username)
|
||||
|
|
|
@ -59,12 +59,13 @@ class TrampolineUIHelper {
|
|||
}
|
||||
|
||||
public promptForGenericGitAuthentication(
|
||||
hostname: string
|
||||
remoteUrl: string,
|
||||
username?: string
|
||||
): Promise<{ username: string; password: string }> {
|
||||
return new Promise(resolve => {
|
||||
this.dispatcher.showPopup({
|
||||
type: PopupType.GenericGitAuthentication,
|
||||
hostname,
|
||||
remoteUrl,
|
||||
onSubmit: (username: string, password: string) =>
|
||||
resolve({ username, password }),
|
||||
onDismiss: () => resolve({ username: '', password: '' }),
|
||||
|
|
|
@ -1925,7 +1925,7 @@ export class App extends React.Component<IAppProps, IAppState> {
|
|||
return (
|
||||
<GenericGitAuthentication
|
||||
key="generic-git-authentication"
|
||||
hostname={popup.hostname}
|
||||
remoteUrl={popup.remoteUrl}
|
||||
// eslint-disable-next-line react/jsx-no-bind
|
||||
onDismiss={onDismiss}
|
||||
onSave={popup.onSubmit}
|
||||
|
|
|
@ -9,14 +9,20 @@ import { LinkButton } from '../lib/link-button'
|
|||
import { PasswordTextBox } from '../lib/password-text-box'
|
||||
|
||||
interface IGenericGitAuthenticationProps {
|
||||
/** The hostname with which the user tried to authenticate. */
|
||||
readonly hostname: string
|
||||
/** The remote url with which the user tried to authenticate. */
|
||||
readonly remoteUrl: string
|
||||
|
||||
/** The function to call when the user saves their credentials. */
|
||||
readonly onSave: (username: string, password: string) => void
|
||||
|
||||
/** The function to call when the user dismisses the dialog. */
|
||||
readonly onDismiss: () => void
|
||||
|
||||
/**
|
||||
* In case the username is predetermined. Setting this will prevent
|
||||
* the popup from allowing the user to change the username.
|
||||
*/
|
||||
readonly username?: string
|
||||
}
|
||||
|
||||
interface IGenericGitAuthenticationState {
|
||||
|
@ -32,7 +38,7 @@ export class GenericGitAuthentication extends React.Component<
|
|||
public constructor(props: IGenericGitAuthenticationProps) {
|
||||
super(props)
|
||||
|
||||
this.state = { username: '', password: '' }
|
||||
this.state = { username: this.props.username ?? '', password: '' }
|
||||
}
|
||||
|
||||
public render() {
|
||||
|
@ -46,18 +52,24 @@ export class GenericGitAuthentication extends React.Component<
|
|||
>
|
||||
<DialogContent>
|
||||
<p>
|
||||
We were unable to authenticate with <Ref>{this.props.hostname}</Ref>
|
||||
. Please enter your username and password to try again.
|
||||
We were unable to authenticate with{' '}
|
||||
<Ref>{this.props.remoteUrl}</Ref>. Please enter{' '}
|
||||
{this.props.username
|
||||
? `the password for the user ${this.props.username}`
|
||||
: 'your username and password'}{' '}
|
||||
to try again.
|
||||
</p>
|
||||
|
||||
<Row>
|
||||
<TextBox
|
||||
label="Username"
|
||||
autoFocus={true}
|
||||
value={this.state.username}
|
||||
onValueChanged={this.onUsernameChange}
|
||||
/>
|
||||
</Row>
|
||||
{this.props.username === undefined && (
|
||||
<Row>
|
||||
<TextBox
|
||||
label="Username"
|
||||
autoFocus={true}
|
||||
value={this.state.username}
|
||||
onValueChanged={this.onUsernameChange}
|
||||
/>
|
||||
</Row>
|
||||
)}
|
||||
|
||||
<Row>
|
||||
<PasswordTextBox
|
||||
|
@ -96,7 +108,10 @@ export class GenericGitAuthentication extends React.Component<
|
|||
}
|
||||
|
||||
private save = () => {
|
||||
this.props.onSave(this.state.username, this.state.password)
|
||||
this.props.onSave(
|
||||
this.props.username ?? this.state.username,
|
||||
this.state.password
|
||||
)
|
||||
this.props.onDismiss()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue