Skip to content

Commit b24086c

Browse files
authored
Merge pull request #518 from mminns/issue/218
Issue/218
2 parents 793a74c + 069cbec commit b24086c

File tree

10 files changed

+864
-156
lines changed

10 files changed

+864
-156
lines changed

docs/configuration.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,34 @@ git config --global credential.bitbucketAuthModes "oauth,basic"
196196

197197
---
198198

199+
### credential.bitbucketAlwaysRefreshCredentials
200+
201+
Forces GCM to ignore any existing stored Basic Auth or OAuth access tokens and always run through the process to refresh the credentials before returning them to Git.
202+
203+
This is especially relevant to OAuth credentials. Bitbucket.org access tokens expire after 2 hours, after that the refresh token must be used to get a new access token.
204+
205+
Enabling this option will improve performance when using Oauth2 and interacting with Bitbucket.org if, on average, commits are done less frequently than every 2 hours.
206+
207+
Enabling this option will decrease performance when using Basic Auth by requiring the user the re-enter credentials everytime.
208+
209+
210+
Value|Refresh Credentials Before Returning
211+
-|-
212+
`true`, `1`, `yes`, `on` |Always
213+
`false`, `0`, `no`, `off`_(default)_|Only when the credentials are found to be invalid
214+
215+
#### Example
216+
217+
```shell
218+
git config --global credential.bitbucketAlwaysRefreshCredentials 1
219+
```
220+
221+
Defaults to false/disabled.
222+
223+
**Also see: [GCM_BITBUCKET_ALWAYS_REFRESH_CREDENTIALS](environment.md#GCM_BITBUCKET_ALWAYS_REFRESH_CREDENTIALS)**
224+
225+
---
226+
199227
### credential.gitHubAuthModes
200228

201229
Override the available authentication modes presented during GitHub authentication.

docs/environment.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,40 @@ export GCM_BITBUCKET_AUTHMODES="oauth,basic"
343343

344344
---
345345

346+
### GCM_BITBUCKET_ALWAYS_REFRESH_CREDENTIALS
347+
348+
Forces GCM to ignore any existing stored Basic Auth or OAuth access tokens and always run through the process to refresh the credentials before returning them to Git.
349+
350+
This is especially relevant to OAuth credentials. Bitbucket.org access tokens expire after 2 hours, after that the refresh token must be used to get a new access token.
351+
352+
Enabling this option will improve performance when using Oauth2 and interacting with Bitbucket.org if, on average, commits are done less frequently than every 2 hours.
353+
354+
Enabling this option will decrease performance when using Basic Auth by requiring the user the re-enter credentials everytime.
355+
356+
357+
Value|Refresh Credentials Before Returning
358+
-|-
359+
`true`, `1`, `yes`, `on` |Always
360+
`false`, `0`, `no`, `off`_(default)_|Only when the credentials are found to be invalid
361+
362+
##### Windows
363+
364+
```batch
365+
SET GCM_BITBUCKET_ALWAYS_REFRESH_CREDENTIALS=1
366+
```
367+
368+
##### macOS/Linux
369+
370+
```bash
371+
export GCM_BITBUCKET_ALWAYS_REFRESH_CREDENTIALS=1
372+
```
373+
374+
Defaults to false/disabled.
375+
376+
**Also see: [credential.bitbucketAlwaysRefreshCredentials](configuration.md#bitbucketAlwaysRefreshCredentials)**
377+
378+
---
379+
346380
### GCM_GITHUB_AUTHMODES
347381

348382
Override the available authentication modes presented during GitHub authentication.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using GitCredentialManager.Tests.Objects;
4+
using Xunit;
5+
6+
namespace Atlassian.Bitbucket.Tests
7+
{
8+
public class BitbucketAuthenticationTest
9+
{
10+
[Theory]
11+
[InlineData("jsquire", "password")]
12+
public async Task BitbucketAuthentication_GetBasicCredentialsAsync_SucceedsAfterUserInput(string username, string password)
13+
{
14+
var context = new TestCommandContext();
15+
context.Terminal.Prompts["Username"] = username;
16+
context.Terminal.SecretPrompts["Password"] = password;
17+
System.Uri targetUri = null;
18+
19+
var bitbucketAuthentication = new BitbucketAuthentication(context);
20+
21+
var result = await bitbucketAuthentication.GetBasicCredentialsAsync(targetUri, username);
22+
23+
Assert.NotNull(result);
24+
Assert.Equal(username, result.Account);
25+
Assert.Equal(password, result.Password);
26+
}
27+
28+
[Fact]
29+
public async Task BitbucketAuthentication_ShowOAuthRequiredPromptAsync_SucceedsAfterUserInput()
30+
{
31+
var context = new TestCommandContext();
32+
context.Terminal.Prompts["Press enter to continue..."] = " ";
33+
34+
var bitbucketAuthentication = new BitbucketAuthentication(context);
35+
36+
var result = await bitbucketAuthentication.ShowOAuthRequiredPromptAsync();
37+
38+
Assert.True(result);
39+
Assert.Equal($"Your account has two-factor authentication enabled.{Environment.NewLine}" +
40+
$"To continue you must complete authentication in your web browser.{Environment.NewLine}", context.Terminal.Messages[0].Item1);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)