Skip to content

Commit e7f6797

Browse files
committed
Bitbucket Server Support: Added ability to set 'bitbucket' as the provier for an arbitrary host, i.e. a Bitbucket Server host
Allow HTTP as well as HTTPS for Bitbucket Server hosts TODO test more complex URLs e.g. https://my.company.com/bitbucket
1 parent 9032ca6 commit e7f6797

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

docs/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ID|Provider
6262
`auto` _(default)_|_\[automatic\]_
6363
`azure-repos`|Azure Repos
6464
`github`|GitHub
65+
`bitbucket`|Bitbucket
6566
`generic`|Generic (any other provider not listed above)
6667

6768
Automatic provider selection is based on the remote URL.
@@ -91,6 +92,7 @@ Authority|Provider(s)
9192
`auto` _(default)_|_\[automatic\]_
9293
`msa`, `microsoft`, `microsoftaccount`,<br/>`aad`, `azure`, `azuredirectory`,</br>`live`, `liveconnect`, `liveid`|Azure Repos<br/>_(supports Microsoft Authentication)_
9394
`github`|GitHub<br/>_(supports GitHub Authentication)_
95+
`bitbucket`|Bitbucket.org<br/>_(supports Basic Authentication and OAuth)_<br/>Bitbucket Server<br/>_(supports Basic Authentication)_
9496
`basic`, `integrated`, `windows`, `kerberos`, `ntlm`,<br/>`tfs`, `sso`|Generic<br/>_(supports Basic and Windows Integrated Authentication)_
9597

9698
#### Example

src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ public bool IsSupported(InputArguments input)
5151

5252
public async Task<ICredential> GetCredentialAsync(InputArguments input)
5353
{
54+
// Compute the target URI
55+
Uri targetUri = GetTargetUri(input);
56+
5457
// We should not allow unencrypted communication and should inform the user
55-
if (StringComparer.OrdinalIgnoreCase.Equals(input.Protocol, "http"))
58+
if (StringComparer.OrdinalIgnoreCase.Equals(input.Protocol, "http")
59+
&& targetUri.Host.Equals(BitbucketConstants.BitbucketBaseUrlHost))
5660
{
5761
throw new Exception("Unencrypted HTTP is not supported for Bitbucket. Ensure the repository remote URL is using HTTPS.");
5862
}
5963

60-
// Compute the target URI
61-
Uri targetUri = GetTargetUri(input);
62-
6364
// Try and get the username specified in the remote URL if any
6465
string targetUriUser = targetUri.GetUserName();
6566

@@ -93,7 +94,7 @@ public async Task<ICredential> GetCredentialAsync(InputArguments input)
9394
// or we have a freshly captured user/pass. Regardless, we must check if these credentials
9495
// pass and two-factor requirement on the account.
9596
_context.Trace.WriteLine("Checking if two-factor requirements for stored credentials...");
96-
bool requires2Fa = await RequiresTwoFactorAuthenticationAsync(credential);
97+
bool requires2Fa = await RequiresTwoFactorAuthenticationAsync(credential, targetUri);
9798
if (!requires2Fa)
9899
{
99100
_context.Trace.WriteLine("Two-factor requirement passed with stored credentials");
@@ -220,8 +221,14 @@ private async Task<string> ResolveOAuthUserNameAsync(string accessToken)
220221
throw new Exception($"Failed to resolve username. HTTP: {result.StatusCode}");
221222
}
222223

223-
private async Task<bool> RequiresTwoFactorAuthenticationAsync(ICredential credentials)
224+
private async Task<bool> RequiresTwoFactorAuthenticationAsync(ICredential credentials, Uri targetUri)
224225
{
226+
if(!targetUri.Host.Equals(BitbucketConstants.BitbucketBaseUrlHost))
227+
{
228+
// BBS
229+
return false;
230+
}
231+
225232
RestApiResult<UserInfo> result = await _bitbucketApi.GetUserInformationAsync(credentials.UserName, credentials.Password, false);
226233
switch (result.StatusCode)
227234
{

0 commit comments

Comments
 (0)