Skip to content

Commit ac6f562

Browse files
flippedcoderrlr
authored andcommitted
New non-polling authentication flow.
- Fixes intermittent hanging during auth - Implements PKCE
1 parent 4c8499d commit ac6f562

File tree

19 files changed

+228
-214
lines changed

19 files changed

+228
-214
lines changed

Diff for: installer/MozillaVPN.wxs

+13-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@
8686
<File Source="../ui/bin/$(var.Platform)/Release/Resources/Graphics/icon_70x70.png" />
8787
<File Source="../ui/bin/$(var.Platform)/Release/Resources/Graphics/icon_150x150.png" />
8888

89+
<!-- Custom URL protocol for handling the PKCE auth flow -->
90+
<RegistryKey Root="HKCR" Key="mozilla-vpn">
91+
<RegistryValue Type="string" Name="URL Protocol" Value="mozilla-vpn"/>
92+
<RegistryValue Type="string" Value="URL:mozilla-vpn Protocol"/>
93+
<RegistryKey Key="DefaultIcon">
94+
<RegistryValue Type="string" Value="MozillaVPN.exe" />
95+
</RegistryKey>
96+
<RegistryKey Key="shell\open\command">
97+
<RegistryValue Type="string" Value="&quot;C:\Program Files\Mozilla\Mozilla VPN\MozillaVPN.exe&quot; &quot;%1&quot;" />
98+
</RegistryKey>
99+
</RegistryKey>
100+
89101
<!-- Broker Service -->
90102
<ServiceInstall
91103
Type="ownProcess"
@@ -112,7 +124,7 @@
112124
</Component>
113125
</ComponentGroup>
114126

115-
<!--
127+
<!--
116128
Merge modules
117129
-->
118130
<DirectoryRef Id="MozillaVPNFolder">

Diff for: ui/src/Firefox Private Network.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@
225225
<EmbedInteropTypes>False</EmbedInteropTypes>
226226
<Private>True</Private>
227227
</Reference>
228+
<Reference Include="Microsoft.IdentityModel.Logging, Version=6.7.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
229+
<HintPath>..\packages\Microsoft.IdentityModel.Logging.6.7.1\lib\net461\Microsoft.IdentityModel.Logging.dll</HintPath>
230+
</Reference>
231+
<Reference Include="Microsoft.IdentityModel.Tokens, Version=6.7.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
232+
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.6.7.1\lib\net461\Microsoft.IdentityModel.Tokens.dll</HintPath>
233+
</Reference>
228234
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
229235
<HintPath>..\packages\Microsoft.WindowsAPICodePack-Core.1.1.0.2\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
230236
</Reference>

Diff for: ui/src/FxA/Account.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public Account()
5050
}
5151
}
5252

53+
/// <summary>
54+
/// Gets or sets the API version for making non-PKCE auth requests and handling responses.
55+
/// </summary>
56+
public static string OriginalApiVersion { get; set; } = "/api/v1";
57+
5358
/// <summary>
5459
/// Gets or sets the config structure associated with this account.
5560
/// </summary>
@@ -73,7 +78,7 @@ public Account()
7378
public bool ProcessLogin(string fxaJson)
7479
{
7580
// Initialize a new login session configuration
76-
Manager.Account.Config = new FxA.Config(fxaJson);
81+
Manager.Account.Config = new Config(fxaJson);
7782

7883
// Sets a value that a user has just logged in
7984
Manager.MainWindowViewModel.NewUserSignIn = true;
@@ -87,14 +92,14 @@ public bool ProcessLogin(string fxaJson)
8792
Manager.Account.Config.WriteFxAUserToFile(ProductConstants.FxAUserFile);
8893

8994
// Set the account login state to logged in
90-
Manager.Account.LoginState = FxA.LoginState.LoggedIn;
95+
Manager.Account.LoginState = LoginState.LoggedIn;
9196

9297
// Initialize cache for avatar image
9398
Manager.Account.Avatar.InitializeCache(avatarUrl: Config.FxALogin.User.Avatar);
9499

95100
// Added a new account device through the FxA API, using the newly generated keypair
96-
var devices = new FxA.Devices();
97-
var deviceName = string.Format("{0} ({1} {2})", System.Environment.MachineName, System.Environment.OSVersion.Platform, System.Environment.OSVersion.Version);
101+
var devices = new Devices();
102+
var deviceName = string.Format("{0} ({1} {2})", Environment.MachineName, Environment.OSVersion.Platform, Environment.OSVersion.Version);
98103
var deviceAddResponse = devices.AddDevice(deviceName, keys.Public);
99104

100105
// Upon successful addition of a new device, save the device interface to the WireGuard configuration file and IP addresses to settings file
@@ -159,7 +164,7 @@ public void Logout(bool removeDevice = false)
159164
/// <returns>FxA user JSON object.</returns>
160165
public JSONStructures.User GetAccountDetails()
161166
{
162-
var api = new ApiRequest(Manager.Account.Config.FxALogin.Token, "/vpn/account", RestSharp.Method.GET);
167+
var api = new ApiRequest(Manager.Account.Config.FxALogin.Token, $"{ProductConstants.BaseUrl}{OriginalApiVersion}/vpn/account", RestSharp.Method.GET);
163168

164169
// Execute the request
165170
var response = api.SendRequest();

Diff for: ui/src/FxA/Devices.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.IO;
78
using System.Threading.Tasks;
89
using Newtonsoft.Json;
910

@@ -22,7 +23,7 @@ internal class Devices
2223
/// <returns>Returns the user's device if successful, otherwise null.</returns>
2324
public JSONStructures.Device AddDevice(string deviceName, string publicKey)
2425
{
25-
var api = new ApiRequest(Manager.Account.Config.FxALogin.Token, "/vpn/device", RestSharp.Method.POST);
26+
var api = new ApiRequest(Manager.Account.Config.FxALogin.Token, $"{ProductConstants.BaseUrl}{Account.OriginalApiVersion}/vpn/device", RestSharp.Method.POST);
2627
api.AddPostBody(new Dictionary<string, string> { { "name", deviceName }, { "pubkey", publicKey } });
2728

2829
// Execute the request
@@ -71,7 +72,7 @@ public bool RemoveDevice(string publicKey, bool safeRemove = false, bool silent
7172

7273
// Url encoding the device public key
7374
var sanitizedDevicePublicKey = System.Web.HttpUtility.UrlEncode(publicKey);
74-
var api = new ApiRequest(Manager.Account.Config.FxALogin.Token, "/vpn/device/" + sanitizedDevicePublicKey, RestSharp.Method.DELETE);
75+
var api = new ApiRequest(Manager.Account.Config.FxALogin.Token, $"{ProductConstants.BaseUrl}{Account.OriginalApiVersion}/vpn/device/" + sanitizedDevicePublicKey, RestSharp.Method.DELETE);
7576

7677
// Execute the request`
7778
var response = api.SendRequest();

0 commit comments

Comments
 (0)