Skip to content

Commit a9507b1

Browse files
author
Thomas Felices
committed
Support for username and password command line args [VPNWIN-2855]
1 parent d823fa7 commit a9507b1

File tree

6 files changed

+155
-3
lines changed

6 files changed

+155
-3
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2024 Proton AG
3+
*
4+
* This file is part of ProtonVPN.
5+
*
6+
* ProtonVPN is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* ProtonVPN is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with ProtonVPN. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
using ProtonVPN.Client.EventMessaging.Contracts;
21+
using ProtonVPN.Client.Handlers.Bases;
22+
using ProtonVPN.Client.Logic.Auth.Contracts.Enums;
23+
using ProtonVPN.Client.Logic.Auth.Contracts.Messages;
24+
using ProtonVPN.Client.Settings.Contracts;
25+
26+
namespace ProtonVPN.Client.Handlers;
27+
28+
public class SessionSettingsHandler : IHandler,
29+
IEventMessageReceiver<AuthenticationStatusChanged>
30+
{
31+
private readonly ISessionSettings _sessionSettings;
32+
33+
public SessionSettingsHandler(
34+
ISessionSettings sessionSettings)
35+
{
36+
_sessionSettings = sessionSettings;
37+
}
38+
39+
public void Receive(AuthenticationStatusChanged message)
40+
{
41+
if (message.AuthenticationStatus != AuthenticationStatus.LoggedOut)
42+
{
43+
_sessionSettings.ClearCredentials();
44+
}
45+
}
46+
}

src/Client/ProtonVPN.Client/Services/Bootstrapping/Bootstrapper.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023 Proton AG
2+
* Copyright (c) 2025 Proton AG
33
*
44
* This file is part of ProtonVPN.
55
*
@@ -19,7 +19,6 @@
1919

2020
using Microsoft.Windows.AppLifecycle;
2121
using ProtonVPN.Client.Common.Dispatching;
22-
using ProtonVPN.Client.Contracts.Services.Browsing;
2322
using ProtonVPN.Client.Core.Services.Activation;
2423
using ProtonVPN.Client.Localization.Contracts;
2524
using ProtonVPN.Client.Logic.Auth.Contracts;
@@ -50,6 +49,7 @@ public class Bootstrapper : IBootstrapper
5049
private readonly IUpdatesManager _updatesManager;
5150
private readonly IGlobalSettingsMigrator _globalSettingsMigrator;
5251
private readonly ISettings _settings;
52+
private readonly ISessionSettings _sessionSettings;
5353
private readonly ILogger _logger;
5454
private readonly IMainWindowActivator _mainWindowActivator;
5555
private readonly IVpnPlanUpdater _vpnPlanUpdater;
@@ -64,6 +64,7 @@ public Bootstrapper(
6464
IUpdatesManager updatesManager,
6565
IGlobalSettingsMigrator settingsMigrator,
6666
ISettings settings,
67+
ISessionSettings sessionSettings,
6768
ILogger logger,
6869
ILocalizationProvider localizer,
6970
IConnectionManager connectionManager,
@@ -80,6 +81,7 @@ public Bootstrapper(
8081
_updatesManager = updatesManager;
8182
_globalSettingsMigrator = settingsMigrator;
8283
_settings = settings;
84+
_sessionSettings = sessionSettings;
8385
_logger = logger;
8486
_mainWindowActivator = mainWindowActivator;
8587
_vpnPlanUpdater = vpnPlanUpdater;
@@ -119,6 +121,7 @@ private void OnCurrentAppInstanceActivated(object? sender, AppActivationArgument
119121
case ExtendedActivationKind.Protocol:
120122
HandleProtocolActivationArguments(e.Data as ProtocolActivatedEventArgs);
121123
break;
124+
122125
default:
123126
_logger.Info<AppLog>($"Handle {e.Kind} activation - Activate window");
124127
_mainWindowActivator.Activate();
@@ -176,6 +179,24 @@ private void HandleCommandLineArguments()
176179
_settings.WireGuardConnectionTimeout = DefaultSettings.WireGuardConnectionTimeout;
177180
}
178181
}
182+
else if (arg.EqualsIgnoringCase("-username") || arg.EqualsIgnoringCase("-u"))
183+
{
184+
int usernameIndex = i + 1;
185+
if (usernameIndex < args.Length)
186+
{
187+
_sessionSettings.Username = args[usernameIndex];
188+
i++;
189+
}
190+
}
191+
else if (arg.EqualsIgnoringCase("-password") || arg.EqualsIgnoringCase("-p"))
192+
{
193+
int passwordIndex = i + 1;
194+
if (passwordIndex < args.Length)
195+
{
196+
_sessionSettings.Password = args[passwordIndex];
197+
i++;
198+
}
199+
}
179200
}
180201

181202
HandleProtonInstallerArguments(args);

src/Client/ProtonVPN.Client/UI/Login/Pages/SignInPageViewModel.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using ProtonVPN.Client.Logic.Auth.Contracts.Messages;
3333
using ProtonVPN.Client.Logic.Auth.Contracts.Models;
3434
using ProtonVPN.Client.Logic.Connection.Contracts.GuestHole;
35+
using ProtonVPN.Client.Settings.Contracts;
3536
using ProtonVPN.Client.UI.Login.Bases;
3637
using ProtonVPN.Client.UI.Login.Enums;
3738
using ProtonVPN.Client.UI.Login.Overlays;
@@ -48,6 +49,7 @@ public partial class SignInPageViewModel : LoginPageViewModelBase
4849
private readonly IEventMessageSender _eventMessageSender;
4950
private readonly IApiAvailabilityVerifier _apiAvailabilityVerifier;
5051
private readonly IGuestHoleManager _guestHoleManager;
52+
private readonly ISessionSettings _sessionSettings;
5153
private readonly SsoLoginOverlayViewModel _ssoLoginOverlayViewModel;
5254

5355
[ObservableProperty]
@@ -114,6 +116,7 @@ public SignInPageViewModel(
114116
IEventMessageSender eventMessageSender,
115117
IApiAvailabilityVerifier apiAvailabilityVerifier,
116118
IGuestHoleManager guestHoleManager,
119+
ISessionSettings sessionSettings,
117120
SsoLoginOverlayViewModel ssoLoginOverlayViewModel,
118121
IViewModelHelper viewModelHelper)
119122
: base(parentViewNavigator, viewModelHelper)
@@ -123,6 +126,7 @@ public SignInPageViewModel(
123126
_eventMessageSender = eventMessageSender;
124127
_apiAvailabilityVerifier = apiAvailabilityVerifier;
125128
_guestHoleManager = guestHoleManager;
129+
_sessionSettings = sessionSettings;
126130
_ssoLoginOverlayViewModel = ssoLoginOverlayViewModel;
127131
}
128132

@@ -185,7 +189,8 @@ private bool ValidateForm()
185189

186190
private bool CanSignIn()
187191
{
188-
return !IsSigningIn;
192+
return !IsSigningIn
193+
&& _userAuthenticator.AuthenticationStatus == AuthenticationStatus.LoggedOut;
189194
}
190195

191196
private async Task<AuthResult> HandleSrpLoginAsync()
@@ -284,6 +289,21 @@ protected override void OnActivated()
284289
base.OnActivated();
285290

286291
_userAuthenticator.ClearUnauthSessionDetails();
292+
293+
if (_userAuthenticator.IsAutoLogin != true && SignInCommand.CanExecute(null))
294+
{
295+
if (!string.IsNullOrEmpty(_sessionSettings.Username))
296+
{
297+
Username = _sessionSettings.Username.Trim();
298+
299+
if (!string.IsNullOrEmpty(_sessionSettings.Password))
300+
{
301+
Password = _sessionSettings.Password.Trim();
302+
303+
SignInCommand.Execute(null);
304+
}
305+
}
306+
}
287307
}
288308

289309
partial void OnSignInFormTypeChanged(SignInFormType oldValue, SignInFormType newValue)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Proton AG
3+
*
4+
* This file is part of ProtonVPN.
5+
*
6+
* ProtonVPN is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* ProtonVPN is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with ProtonVPN. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
namespace ProtonVPN.Client.Settings.Contracts;
21+
22+
public interface ISessionSettings
23+
{
24+
string Username { get; set; }
25+
26+
string Password { get; set; }
27+
28+
void ClearCredentials();
29+
}

src/Client/Settings/ProtonVPN.Client.Settings.Installers/SettingsModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected override void Load(ContainerBuilder builder)
3434
{
3535
builder.RegisterType<Settings>().As<ISettings>().SingleInstance();
3636
builder.RegisterType<GlobalSettings>().As<IGlobalSettings>().SingleInstance();
37+
builder.RegisterType<SessionSettings>().As<ISessionSettings>().SingleInstance();
3738

3839
builder.RegisterType<UserSettingsFileReaderWriter>().As<IUserSettingsFileReaderWriter>().SingleInstance();
3940
builder.RegisterType<GlobalSettingsFileReaderWriter>().As<IGlobalSettingsFileReaderWriter>().SingleInstance();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2025 Proton AG
3+
*
4+
* This file is part of ProtonVPN.
5+
*
6+
* ProtonVPN is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* ProtonVPN is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with ProtonVPN. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
using ProtonVPN.Client.Settings.Contracts;
21+
22+
namespace ProtonVPN.Client.Settings;
23+
24+
public class SessionSettings : ISessionSettings
25+
{
26+
public string Username { get; set; } = string.Empty;
27+
28+
public string Password { get; set; } = string.Empty;
29+
30+
public void ClearCredentials()
31+
{
32+
Username = string.Empty;
33+
Password = string.Empty;
34+
}
35+
}

0 commit comments

Comments
 (0)