|
4 | 4 | using System.Text;
|
5 | 5 | using System.Threading;
|
6 | 6 | using System.Threading.Tasks;
|
| 7 | +using Atlassian.Bitbucket.UI.ViewModels; |
| 8 | +using Atlassian.Bitbucket.UI.Views; |
7 | 9 | using GitCredentialManager;
|
8 | 10 | using GitCredentialManager.Authentication;
|
9 | 11 | using GitCredentialManager.Authentication.OAuth;
|
| 12 | +using GitCredentialManager.UI; |
10 | 13 |
|
11 | 14 | namespace Atlassian.Bitbucket
|
12 | 15 | {
|
@@ -89,15 +92,51 @@ public async Task<CredentialsPromptResult> GetCredentialsAsync(Uri targetUri, st
|
89 | 92 | }
|
90 | 93 |
|
91 | 94 | // Shell out to the UI helper and show the Bitbucket u/p prompt
|
92 |
| - if (Context.Settings.IsGuiPromptsEnabled && Context.SessionManager.IsDesktopSession && |
93 |
| - TryFindHelperCommand(out string helperCommand, out string args)) |
| 95 | + if (Context.Settings.IsGuiPromptsEnabled && Context.SessionManager.IsDesktopSession) |
94 | 96 | {
|
95 |
| - return await GetCredentialsViaHelperAsync(targetUri, userName, modes, helperCommand, args); |
| 97 | + if (TryFindHelperCommand(out string helperCommand, out string args)) |
| 98 | + { |
| 99 | + return await GetCredentialsViaHelperAsync(targetUri, userName, modes, helperCommand, args); |
| 100 | + } |
| 101 | + |
| 102 | + return await GetCredentialsViaUiAsync(targetUri, userName, modes); |
96 | 103 | }
|
97 | 104 |
|
98 | 105 | return GetCredentialsViaTty(targetUri, userName, modes);
|
99 | 106 | }
|
100 | 107 |
|
| 108 | + private async Task<CredentialsPromptResult> GetCredentialsViaUiAsync( |
| 109 | + Uri targetUri, string userName, AuthenticationModes modes) |
| 110 | + { |
| 111 | + var viewModel = new CredentialsViewModel(Context.Environment) |
| 112 | + { |
| 113 | + Url = targetUri, |
| 114 | + UserName = userName, |
| 115 | + ShowOAuth = (modes & AuthenticationModes.OAuth) != 0, |
| 116 | + ShowBasic = (modes & AuthenticationModes.Basic) != 0 |
| 117 | + }; |
| 118 | + |
| 119 | + await AvaloniaUi.ShowViewAsync<CredentialsView>(viewModel, GetParentWindowHandle(), CancellationToken.None); |
| 120 | + |
| 121 | + ThrowIfWindowCancelled(viewModel); |
| 122 | + |
| 123 | + switch (viewModel.SelectedMode) |
| 124 | + { |
| 125 | + case AuthenticationModes.OAuth: |
| 126 | + return new CredentialsPromptResult(AuthenticationModes.OAuth); |
| 127 | + |
| 128 | + case AuthenticationModes.Basic: |
| 129 | + return new CredentialsPromptResult( |
| 130 | + AuthenticationModes.Basic, |
| 131 | + new GitCredential(viewModel.UserName, viewModel.Password) |
| 132 | + ); |
| 133 | + |
| 134 | + default: |
| 135 | + throw new ArgumentOutOfRangeException(nameof(AuthenticationModes), |
| 136 | + "Unknown authentication mode", viewModel.SelectedMode.ToString()); |
| 137 | + } |
| 138 | + } |
| 139 | + |
101 | 140 | private CredentialsPromptResult GetCredentialsViaTty(Uri targetUri, string userName, AuthenticationModes modes)
|
102 | 141 | {
|
103 | 142 | ThrowIfTerminalPromptsDisabled();
|
|
0 commit comments