Skip to content

Commit 072a76d

Browse files
authored
Release 2.7.2 (#2267)
**Changes:** - #2256 - #2258 - #2257
2 parents aff4a59 + cb4afc0 commit 072a76d

33 files changed

+300
-207
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.1.0
1+
2.7.2.0

src/shared/Atlassian.Bitbucket/BitbucketAuthentication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async Task<CredentialsPromptResult> GetCredentialsAsync(Uri targetUri, st
108108
private async Task<CredentialsPromptResult> GetCredentialsViaUiAsync(
109109
Uri targetUri, string userName, AuthenticationModes modes)
110110
{
111-
var viewModel = new CredentialsViewModel(Context.Environment)
111+
var viewModel = new CredentialsViewModel(Context.SessionManager)
112112
{
113113
ShowOAuth = (modes & AuthenticationModes.OAuth) != 0,
114114
ShowBasic = (modes & AuthenticationModes.Basic) != 0
@@ -259,7 +259,7 @@ public async Task<OAuth2TokenResult> CreateOAuthCredentialsAsync(InputArguments
259259
FailureResponseHtmlFormat = BitbucketResources.AuthenticationResponseFailureHtmlFormat
260260
};
261261

262-
var browser = new OAuth2SystemWebBrowser(Context.Environment, browserOptions);
262+
var browser = new OAuth2SystemWebBrowser(Context.SessionManager, browserOptions);
263263
var oauth2Client = _oauth2ClientRegistry.Get(input);
264264

265265
var authCodeResult = await oauth2Client.GetAuthorizationCodeAsync(browser, CancellationToken.None);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected CredentialsCommand(ICommandContext context)
3232

3333
private async Task<int> ExecuteAsync(Uri url, string userName, bool showOAuth, bool showBasic)
3434
{
35-
var viewModel = new CredentialsViewModel(Context.Environment)
35+
var viewModel = new CredentialsViewModel(Context.SessionManager)
3636
{
3737
Url = url,
3838
UserName = userName,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Atlassian.Bitbucket.UI.ViewModels
99
{
1010
public class CredentialsViewModel : WindowViewModel
1111
{
12-
private readonly IEnvironment _environment;
12+
private readonly ISessionManager _sessionManager;
1313

1414
private Uri _url;
1515
private string _userName;
@@ -22,11 +22,11 @@ public CredentialsViewModel()
2222
// Constructor the XAML designer
2323
}
2424

25-
public CredentialsViewModel(IEnvironment environment)
25+
public CredentialsViewModel(ISessionManager sessionManager)
2626
{
27-
EnsureArgument.NotNull(environment, nameof(environment));
27+
EnsureArgument.NotNull(sessionManager, nameof(sessionManager));
2828

29-
_environment = environment;
29+
_sessionManager = sessionManager;
3030

3131
Title = "Connect to Bitbucket";
3232
LoginCommand = new RelayCommand(AcceptBasic, CanLogin);
@@ -77,7 +77,7 @@ private void ForgotPassword()
7777
? new Uri(BitbucketConstants.HelpUrls.PasswordReset)
7878
: new Uri(_url, BitbucketConstants.HelpUrls.DataCenterPasswordReset);
7979

80-
BrowserUtils.OpenDefaultBrowser(_environment, passwordResetUri);
80+
_sessionManager.OpenBrowser(passwordResetUri);
8181
}
8282

8383
private void SignUp()
@@ -86,7 +86,7 @@ private void SignUp()
8686
? new Uri(BitbucketConstants.HelpUrls.SignUp)
8787
: new Uri(_url, BitbucketConstants.HelpUrls.DataCenterLogin);
8888

89-
BrowserUtils.OpenDefaultBrowser(_environment, signUpUri);
89+
_sessionManager.OpenBrowser(signUpUri);
9090
}
9191

9292
public Uri Url

src/shared/Core.Tests/Authentication/OAuth2SystemWebBrowserTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class OAuth2SystemWebBrowserTests
1010
[Fact]
1111
public void OAuth2SystemWebBrowser_UpdateRedirectUri_NonLoopback_ThrowsError()
1212
{
13-
var env = new TestEnvironment();
13+
var sm = new TestSessionManager();
1414
var options = new OAuth2WebBrowserOptions();
15-
var browser = new OAuth2SystemWebBrowser(env, options);
15+
var browser = new OAuth2SystemWebBrowser(sm, options);
1616

1717
Assert.Throws<ArgumentException>(() => browser.UpdateRedirectUri(new Uri("http://example.com")));
1818
}
@@ -28,9 +28,9 @@ public void OAuth2SystemWebBrowser_UpdateRedirectUri_NonLoopback_ThrowsError()
2828
[InlineData("http://127.0.0.7:1234/oauth-callback/", "http://127.0.0.7:1234/oauth-callback/")]
2929
public void OAuth2SystemWebBrowser_UpdateRedirectUri_SpecificPort(string input, string expected)
3030
{
31-
var env = new TestEnvironment();
31+
var sm = new TestSessionManager();
3232
var options = new OAuth2WebBrowserOptions();
33-
var browser = new OAuth2SystemWebBrowser(env, options);
33+
var browser = new OAuth2SystemWebBrowser(sm, options);
3434

3535
Uri actualUri = browser.UpdateRedirectUri(new Uri(input));
3636

@@ -48,9 +48,9 @@ public void OAuth2SystemWebBrowser_UpdateRedirectUri_SpecificPort(string input,
4848
[InlineData("http://127.0.0.7/oauth-callback/")]
4949
public void OAuth2SystemWebBrowser_UpdateRedirectUri_AnyPort(string input)
5050
{
51-
var env = new TestEnvironment();
51+
var sm = new TestSessionManager();
5252
var options = new OAuth2WebBrowserOptions();
53-
var browser = new OAuth2SystemWebBrowser(env, options);
53+
var browser = new OAuth2SystemWebBrowser(sm, options);
5454

5555
var inputUri = new Uri(input);
5656
Uri actualUri = browser.UpdateRedirectUri(inputUri);

src/shared/Core/Authentication/MicrosoftAuthentication.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private async Task<bool> UseDefaultAccountAsync(string userName)
336336
}
337337
}
338338

339-
var viewModel = new DefaultAccountViewModel(Context.Environment)
339+
var viewModel = new DefaultAccountViewModel(Context.SessionManager)
340340
{
341341
UserName = userName
342342
};
@@ -754,10 +754,33 @@ private static EmbeddedWebViewOptions GetEmbeddedWebViewOptions()
754754
};
755755
}
756756

757-
private static SystemWebViewOptions GetSystemWebViewOptions()
757+
private SystemWebViewOptions GetSystemWebViewOptions()
758758
{
759759
// TODO: add nicer HTML success and error pages
760-
return new SystemWebViewOptions();
760+
return new SystemWebViewOptions
761+
{
762+
OpenBrowserAsync = OpenBrowserFunc
763+
};
764+
765+
// We have special handling for Linux and WSL to open the system browser
766+
// so we need to use our own function here. Sorry MSAL!
767+
Task OpenBrowserFunc(Uri uri)
768+
{
769+
try
770+
{
771+
Context.SessionManager.OpenBrowser(uri);
772+
}
773+
catch (Exception ex)
774+
{
775+
Context.Trace.WriteLine("Failed to open system web browser - using MSAL fallback");
776+
Context.Trace.WriteException(ex);
777+
778+
// Fallback to MSAL's default browser opening logic, preferring Edge.
779+
return SystemWebViewOptions.OpenWithChromeEdgeBrowserAsync(uri);
780+
}
781+
782+
return Task.CompletedTask;
783+
}
761784
}
762785

763786
private Task ShowDeviceCodeInTty(DeviceCodeResult dcr)
@@ -859,8 +882,14 @@ private void EnsureCanUseEmbeddedWebView()
859882

860883
private bool CanUseSystemWebView(IPublicClientApplication app, Uri redirectUri)
861884
{
885+
//
862886
// MSAL requires the application redirect URI is a loopback address to use the System WebView
863-
return Context.SessionManager.IsWebBrowserAvailable && app.IsSystemWebViewAvailable && redirectUri.IsLoopback;
887+
//
888+
// Note: we do NOT check the MSAL 'IsSystemWebViewAvailable' property as it only
889+
// looks for the presence of the DISPLAY environment variable on UNIX systems.
890+
// This is insufficient as we instead handle launching the default browser ourselves.
891+
//
892+
return Context.SessionManager.IsWebBrowserAvailable && redirectUri.IsLoopback;
864893
}
865894

866895
private void EnsureCanUseSystemWebView(IPublicClientApplication app, Uri redirectUri)
@@ -871,12 +900,6 @@ private void EnsureCanUseSystemWebView(IPublicClientApplication app, Uri redirec
871900
"System web view is not available without a way to start a browser.");
872901
}
873902

874-
if (!app.IsSystemWebViewAvailable)
875-
{
876-
throw new Trace2InvalidOperationException(Context.Trace2,
877-
"System web view is not available on this platform.");
878-
}
879-
880903
if (!redirectUri.IsLoopback)
881904
{
882905
throw new Trace2InvalidOperationException(Context.Trace2,

src/shared/Core/Authentication/OAuth/OAuth2SystemWebBrowser.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.Net;
54
using System.Net.Sockets;
65
using System.Threading;
@@ -33,15 +32,15 @@ public class OAuth2WebBrowserOptions
3332

3433
public class OAuth2SystemWebBrowser : IOAuth2WebBrowser
3534
{
36-
private readonly IEnvironment _environment;
35+
private readonly ISessionManager _sessionManager;
3736
private readonly OAuth2WebBrowserOptions _options;
3837

39-
public OAuth2SystemWebBrowser(IEnvironment environment, OAuth2WebBrowserOptions options)
38+
public OAuth2SystemWebBrowser(ISessionManager sessionManager, OAuth2WebBrowserOptions options)
4039
{
41-
EnsureArgument.NotNull(environment, nameof(environment));
40+
EnsureArgument.NotNull(sessionManager, nameof(sessionManager));
4241
EnsureArgument.NotNull(options, nameof(options));
4342

44-
_environment = environment;
43+
_sessionManager = sessionManager;
4544
_options = options;
4645
}
4746

@@ -71,7 +70,7 @@ public async Task<Uri> GetAuthenticationCodeAsync(Uri authorizationUri, Uri redi
7170

7271
Task<Uri> interceptTask = InterceptRequestsAsync(redirectUri, ct);
7372

74-
BrowserUtils.OpenDefaultBrowser(_environment, authorizationUri);
73+
_sessionManager.OpenBrowser(authorizationUri);
7574

7675
return await interceptTask;
7776
}

src/shared/Core/Authentication/OAuthAuthentication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public async Task<OAuth2TokenResult> GetTokenByBrowserAsync(OAuth2Client client,
187187
}
188188

189189
var browserOptions = new OAuth2WebBrowserOptions();
190-
var browser = new OAuth2SystemWebBrowser(Context.Environment, browserOptions);
190+
var browser = new OAuth2SystemWebBrowser(Context.SessionManager, browserOptions);
191191
var authCode = await client.GetAuthorizationCodeAsync(scopes, browser, CancellationToken.None);
192192
return await client.GetTokenByAuthorizationCodeAsync(authCode, CancellationToken.None);
193193
}
@@ -241,7 +241,7 @@ public async Task<OAuth2TokenResult> GetTokenByDeviceCodeAsync(OAuth2Client clie
241241

242242
private Task ShowDeviceCodeViaUiAsync(OAuth2DeviceCodeResult dcr, CancellationToken ct)
243243
{
244-
var viewModel = new DeviceCodeViewModel(Context.Environment)
244+
var viewModel = new DeviceCodeViewModel(Context.SessionManager)
245245
{
246246
UserCode = dcr.UserCode,
247247
VerificationUrl = dcr.VerificationUri.ToString(),

src/shared/Core/BrowserUtils.cs

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/shared/Core/CommandContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public CommandContext()
103103
{
104104
FileSystem = new WindowsFileSystem();
105105
Environment = new WindowsEnvironment(FileSystem);
106-
SessionManager = new WindowsSessionManager(Environment, FileSystem);
106+
SessionManager = new WindowsSessionManager(Trace, Environment, FileSystem);
107107
ProcessManager = new WindowsProcessManager(Trace2);
108108
Terminal = new WindowsTerminal(Trace, Trace2);
109109
string gitPath = GetGitPath(Environment, FileSystem, Trace);
@@ -120,7 +120,7 @@ public CommandContext()
120120
{
121121
FileSystem = new MacOSFileSystem();
122122
Environment = new MacOSEnvironment(FileSystem);
123-
SessionManager = new MacOSSessionManager(Environment, FileSystem);
123+
SessionManager = new MacOSSessionManager(Trace, Environment, FileSystem);
124124
ProcessManager = new ProcessManager(Trace2);
125125
Terminal = new MacOSTerminal(Trace, Trace2);
126126
string gitPath = GetGitPath(Environment, FileSystem, Trace);
@@ -137,7 +137,7 @@ public CommandContext()
137137
{
138138
FileSystem = new LinuxFileSystem();
139139
Environment = new PosixEnvironment(FileSystem);
140-
SessionManager = new LinuxSessionManager(Environment, FileSystem);
140+
SessionManager = new LinuxSessionManager(Trace, Environment, FileSystem);
141141
ProcessManager = new ProcessManager(Trace2);
142142
Terminal = new LinuxTerminal(Trace, Trace2);
143143
string gitPath = GetGitPath(Environment, FileSystem, Trace);

0 commit comments

Comments
 (0)