Skip to content

Commit e4d4f16

Browse files
committed
bitbucket: show on-prem URL in UI and use better help links
Update the Bitbucket credential UI to show the URL of the Bitbucket Server or Data Center instance, if we're talking to them. Also fix up the help links to point to a host-relative location; not always to Bitbucket Cloud pages. Note that the OAuth prompt will never been shown for Server/DC since 2FA is not supported there.
1 parent 14ff019 commit e4d4f16

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

src/shared/Atlassian.Bitbucket.UI.Avalonia/Views/CredentialsView.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<StackPanel DockPanel.Dock="Top" Margin="0,0,0,30">
2424
<Image HorizontalAlignment="Center" Source="/Assets/atlassian-logo.png" />
2525
<TextBlock HorizontalAlignment="Center" Text="Log in to your account"/>
26+
<TextBlock HorizontalAlignment="Center" Text="{Binding Url}"
27+
IsVisible="{Binding Url, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
28+
Margin="0,10,0,0"/>
2629
</StackPanel>
2730

2831
<StackPanel Width="288">

src/shared/Atlassian.Bitbucket.UI/Commands/CredentialsCommand.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public abstract class CredentialsCommand : HelperCommand
1515
protected CredentialsCommand(ICommandContext context)
1616
: base(context, "userpass", "Show authentication prompt.")
1717
{
18+
AddOption(
19+
new Option<string>("--url", "Bitbucket Server or Data Center URL")
20+
);
21+
1822
AddOption(
1923
new Option<string>("--username", "Username or email.")
2024
);
@@ -23,13 +27,14 @@ protected CredentialsCommand(ICommandContext context)
2327
new Option("--show-oauth", "Show OAuth option.")
2428
);
2529

26-
Handler = CommandHandler.Create<string, bool>(ExecuteAsync);
30+
Handler = CommandHandler.Create<Uri, string, bool>(ExecuteAsync);
2731
}
2832

29-
private async Task<int> ExecuteAsync(string userName, bool showOAuth)
33+
private async Task<int> ExecuteAsync(Uri url, string userName, bool showOAuth)
3034
{
3135
var viewModel = new CredentialsViewModel(Context.Environment)
3236
{
37+
Url = url,
3338
UserName = userName,
3439
ShowOAuth = showOAuth
3540
};

src/shared/Atlassian.Bitbucket.UI/Commands/OAuthCommand.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.CommandLine;
34
using System.CommandLine.Invocation;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -14,6 +15,10 @@ public abstract class OAuthCommand : HelperCommand
1415
protected OAuthCommand(ICommandContext context)
1516
: base(context, "oauth", "Show OAuth required prompt.")
1617
{
18+
AddOption(
19+
new Option<string>("--url", "Bitbucket Server or Data Center URL")
20+
);
21+
1722
Handler = CommandHandler.Create(ExecuteAsync);
1823
}
1924

src/shared/Atlassian.Bitbucket.UI/ViewModels/CredentialsViewModel.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.ComponentModel;
23
using System.Windows.Input;
34
using GitCredentialManager;
@@ -10,6 +11,7 @@ public class CredentialsViewModel : WindowViewModel
1011
{
1112
private readonly IEnvironment _environment;
1213

14+
private Uri _url;
1315
private string _userName;
1416
private string _password;
1517
private bool _showOAuth;
@@ -64,12 +66,26 @@ private bool CanAcceptOAuth()
6466

6567
private void ForgotPassword()
6668
{
67-
BrowserUtils.OpenDefaultBrowser(_environment, "https://bitbucket.org/account/password/reset/");
69+
Uri passwordResetUri = _url is null
70+
? new Uri(BitbucketConstants.HelpUrls.PasswordReset)
71+
: new Uri(_url, BitbucketConstants.HelpUrls.DataCenterPasswordReset);
72+
73+
BrowserUtils.OpenDefaultBrowser(_environment, passwordResetUri);
6874
}
6975

7076
private void SignUp()
7177
{
72-
BrowserUtils.OpenDefaultBrowser(_environment, "https://bitbucket.org/account/signup/");
78+
Uri signUpUri = _url is null
79+
? new Uri(BitbucketConstants.HelpUrls.SignUp)
80+
: new Uri(_url, BitbucketConstants.HelpUrls.DataCenterLogin);
81+
82+
BrowserUtils.OpenDefaultBrowser(_environment, signUpUri);
83+
}
84+
85+
public Uri Url
86+
{
87+
get => _url;
88+
set => SetAndRaisePropertyChanged(ref _url, value);
7389
}
7490

7591
public string UserName

src/shared/Atlassian.Bitbucket.UI/ViewModels/OAuthViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ public OAuthViewModel(IEnvironment environment)
3030

3131
private void LearnMore()
3232
{
33-
BrowserUtils.OpenDefaultBrowser(_environment, "https://confluence.atlassian.com/bitbucket/two-step-verification-777023203.html");
33+
// 2FA is not supported on Server/DC so this prompt will never be seen outside of Bitbucket Cloud
34+
BrowserUtils.OpenDefaultBrowser(_environment, BitbucketConstants.HelpUrls.TwoFactor);
3435
}
3536

3637
private void ForgotPassword()
3738
{
38-
BrowserUtils.OpenDefaultBrowser(_environment, "https://bitbucket.org/account/password/reset/");
39+
BrowserUtils.OpenDefaultBrowser(_environment, BitbucketConstants.HelpUrls.PasswordReset);
3940
}
4041

4142
private void SignUp()
4243
{
43-
BrowserUtils.OpenDefaultBrowser(_environment, "https://bitbucket.org/account/signup/");
44+
BrowserUtils.OpenDefaultBrowser(_environment, BitbucketConstants.HelpUrls.SignUp);
4445
}
4546

4647
/// <summary>

src/shared/Atlassian.Bitbucket/BitbucketAuthentication.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public async Task<CredentialsPromptResult> GetCredentialsAsync(Uri targetUri, st
9494
TryFindHelperExecutablePath(out string helperPath))
9595
{
9696
var cmdArgs = new StringBuilder("userpass");
97+
if (!BitbucketHostProvider.IsBitbucketOrg(targetUri))
98+
{
99+
cmdArgs.AppendFormat(" --url {0}", QuoteCmdArg(targetUri.ToString()));
100+
}
101+
97102
if (!string.IsNullOrWhiteSpace(userName))
98103
{
99104
cmdArgs.AppendFormat(" --username {0}", QuoteCmdArg(userName));

src/shared/Atlassian.Bitbucket/BitbucketConstants.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ public static class Credential
4949
}
5050
}
5151

52+
public static class HelpUrls
53+
{
54+
public const string DataCenterPasswordReset = "/passwordreset";
55+
public const string DataCenterLogin = "/login";
56+
public const string PasswordReset = "https://bitbucket.org/account/password/reset/";
57+
public const string SignUp = "https://bitbucket.org/account/signup/";
58+
public const string TwoFactor = "https://support.atlassian.com/bitbucket-cloud/docs/enable-two-step-verification/";
59+
}
60+
5261
/// <summary>
5362
/// Supported authentication modes for Bitbucket.org
5463
/// </summary>

0 commit comments

Comments
 (0)