|
7 | 7 | using GitCredentialManager;
|
8 | 8 | using GitCredentialManager.Authentication;
|
9 | 9 | using GitCredentialManager.Authentication.OAuth;
|
| 10 | +using GitCredentialManager.UI; |
| 11 | +using GitLab.UI.ViewModels; |
| 12 | +using GitLab.UI.Views; |
10 | 13 |
|
11 | 14 | namespace GitLab
|
12 | 15 | {
|
@@ -67,15 +70,66 @@ public async Task<AuthenticationPromptResult> GetAuthenticationAsync(Uri targetU
|
67 | 70 | throw new ArgumentException(@$"Must specify at least one {nameof(AuthenticationModes)}", nameof(modes));
|
68 | 71 | }
|
69 | 72 |
|
70 |
| - if (Context.Settings.IsGuiPromptsEnabled && Context.SessionManager.IsDesktopSession && |
71 |
| - TryFindHelperCommand(out string helperCommand, out string args)) |
| 73 | + if (Context.Settings.IsGuiPromptsEnabled && Context.SessionManager.IsDesktopSession) |
72 | 74 | {
|
73 |
| - return await GetAuthenticationViaHelperAsync(targetUri, userName, modes, helperCommand, args); |
| 75 | + if (TryFindHelperCommand(out string helperCommand, out string args)) |
| 76 | + { |
| 77 | + return await GetAuthenticationViaHelperAsync(targetUri, userName, modes, helperCommand, args); |
| 78 | + } |
| 79 | + |
| 80 | + return await GetAuthenticationViaUiAsync(targetUri, userName, modes); |
74 | 81 | }
|
75 | 82 |
|
76 | 83 | return GetAuthenticationViaTty(targetUri, userName, modes);
|
77 | 84 | }
|
78 | 85 |
|
| 86 | + private async Task<AuthenticationPromptResult> GetAuthenticationViaUiAsync( |
| 87 | + Uri targetUri, string userName, AuthenticationModes modes) |
| 88 | + { |
| 89 | + var viewModel = new CredentialsViewModel(Context.Environment) |
| 90 | + { |
| 91 | + ShowBrowserLogin = (modes & AuthenticationModes.Browser) != 0, |
| 92 | + ShowTokenLogin = (modes & AuthenticationModes.Pat) != 0, |
| 93 | + ShowBasicLogin = (modes & AuthenticationModes.Basic) != 0, |
| 94 | + }; |
| 95 | + |
| 96 | + if (!GitLabConstants.IsGitLabDotCom(targetUri)) |
| 97 | + { |
| 98 | + viewModel.Url = targetUri.ToString(); |
| 99 | + } |
| 100 | + |
| 101 | + if (!string.IsNullOrWhiteSpace(userName)) |
| 102 | + { |
| 103 | + viewModel.UserName = userName; |
| 104 | + viewModel.TokenUserName = userName; |
| 105 | + } |
| 106 | + |
| 107 | + await AvaloniaUi.ShowViewAsync<CredentialsView>(viewModel, GetParentWindowHandle(), CancellationToken.None); |
| 108 | + |
| 109 | + ThrowIfWindowCancelled(viewModel); |
| 110 | + |
| 111 | + switch (viewModel.SelectedMode) |
| 112 | + { |
| 113 | + case AuthenticationModes.Basic: |
| 114 | + return new AuthenticationPromptResult( |
| 115 | + AuthenticationModes.Basic, |
| 116 | + new GitCredential(viewModel.UserName, viewModel.Password) |
| 117 | + ); |
| 118 | + |
| 119 | + case AuthenticationModes.Browser: |
| 120 | + return new AuthenticationPromptResult(AuthenticationModes.Browser); |
| 121 | + |
| 122 | + case AuthenticationModes.Pat: |
| 123 | + return new AuthenticationPromptResult( |
| 124 | + AuthenticationModes.Pat, |
| 125 | + new GitCredential(viewModel.TokenUserName, viewModel.Token) |
| 126 | + ); |
| 127 | + |
| 128 | + default: |
| 129 | + throw new ArgumentOutOfRangeException(); |
| 130 | + } |
| 131 | + } |
| 132 | + |
79 | 133 | private AuthenticationPromptResult GetAuthenticationViaTty(Uri targetUri, string userName, AuthenticationModes modes)
|
80 | 134 | {
|
81 | 135 | switch (modes)
|
|
0 commit comments