Skip to content

Commit 1ea2c0e

Browse files
Fix GitHub cloud backup OAuth configuration
1 parent 4cafbcb commit 1ea2c0e

6 files changed

Lines changed: 91 additions & 15 deletions

File tree

.github/workflows/build-release.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ jobs:
8989
permissions:
9090
contents: read
9191
env:
92+
UNIGETUI_GITHUB_CLIENT_ID: ${{ secrets.UNIGETUI_GITHUB_CLIENT_ID }}
93+
UNIGETUI_GITHUB_CLIENT_SECRET: ${{ secrets.UNIGETUI_GITHUB_CLIENT_SECRET }}
9294
NUGET_PACKAGES: ${{ github.workspace }}\.nuget\packages
9395
strategy:
9496
fail-fast: false
@@ -99,6 +101,19 @@ jobs:
99101
- name: Checkout
100102
uses: actions/checkout@v6
101103

104+
- name: Validate GitHub OAuth secrets
105+
shell: pwsh
106+
run: |
107+
if ([string]::IsNullOrWhiteSpace($env:UNIGETUI_GITHUB_CLIENT_ID)) {
108+
throw "UNIGETUI_GITHUB_CLIENT_ID is not configured for this build environment."
109+
}
110+
111+
if ([string]::IsNullOrWhiteSpace($env:UNIGETUI_GITHUB_CLIENT_SECRET)) {
112+
throw "UNIGETUI_GITHUB_CLIENT_SECRET is not configured for this build environment."
113+
}
114+
115+
Write-Host "::notice::GitHub OAuth secrets are configured for this build."
116+
102117
- name: Install .NET
103118
uses: actions/setup-dotnet@v5
104119
with:

src/UniGetUI/Pages/DialogPages/DialogHelper_Generic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public static async Task ShowTelemetryDialog()
488488
p.Inlines.Add(new LineBreak());
489489
var link = new Hyperlink
490490
{
491-
NavigateUri = new Uri("https://www.marticliment.com/unigetui/privacy/"),
491+
NavigateUri = new Uri("https://devolutions.net/legal/"),
492492
};
493493
link.Inlines.Add(
494494
new Run

src/UniGetUI/Pages/SettingsPages/GeneralPages/Backup.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private void EnablePackageBackupCheckBox_CLOUD_StateChanged(object? sender, Even
354354

355355
private void MoreInfoBtn_OnClick(object sender, RoutedEventArgs e)
356356
{
357-
MainApp.Instance.MainWindow.NavigationPage.ShowHelp("cloud-backup-overview/");
357+
CoreTools.Launch("https://devolutions.net/unigetui");
358358
}
359359
}
360360
}

src/UniGetUI/Services/GitHubAuthService.cs

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace UniGetUI.Services
1212
{
1313
public class GitHubAuthService
1414
{
15+
private const string MissingClientId = "CLIENT_ID_UNSET";
16+
private const string MissingClientSecret = "CLIENT_SECRET_UNSET";
17+
private static readonly TimeSpan LoginTimeout = TimeSpan.FromMinutes(2);
1518
private readonly string GitHubClientId = Secrets.GetGitHubClientId();
1619
private readonly string GitHubClientSecret = Secrets.GetGitHubClientSecret();
1720
private const string RedirectUri = "http://127.0.0.1:58642/";
@@ -47,6 +50,15 @@ public async Task<bool> SignInAsync()
4750
{
4851
try
4952
{
53+
if (!HasConfiguredOAuthClient())
54+
{
55+
Logger.Error(
56+
"GitHub sign-in is not configured for this build. Missing OAuth client ID or client secret."
57+
);
58+
AuthStatusChanged?.Invoke(this, EventArgs.Empty);
59+
return false;
60+
}
61+
5062
Logger.Info("Initiating GitHub sign-in process using loopback redirect...");
5163

5264
var request = new OauthLoginRequest(GitHubClientId)
@@ -74,15 +86,25 @@ public async Task<bool> SignInAsync()
7486
loginBackend = new GHAuthApiRunner();
7587
loginBackend.OnLogin += BackgroundApiOnOnLogin;
7688
await loginBackend.Start();
77-
await Launcher.LaunchUriAsync(oauthLoginUrl);
7889

79-
while (codeFromAPI is null)
90+
bool launchSucceeded = await Launcher.LaunchUriAsync(oauthLoginUrl);
91+
if (!launchSucceeded)
92+
{
93+
Logger.Error("Failed to launch the browser for GitHub sign-in.");
94+
AuthStatusChanged?.Invoke(this, EventArgs.Empty);
95+
return false;
96+
}
97+
98+
DateTime timeoutAt = DateTime.UtcNow.Add(LoginTimeout);
99+
while (codeFromAPI is null && DateTime.UtcNow < timeoutAt)
80100
await Task.Delay(100);
81101

82-
loginBackend.OnLogin -= BackgroundApiOnOnLogin;
83-
await loginBackend.Stop();
84-
loginBackend.Dispose();
85-
loginBackend = null;
102+
if (string.IsNullOrEmpty(codeFromAPI))
103+
{
104+
Logger.Error("GitHub sign-in timed out before the loopback callback was received.");
105+
AuthStatusChanged?.Invoke(this, EventArgs.Empty);
106+
return false;
107+
}
86108

87109
return await _completeSignInAsync(codeFromAPI);
88110
}
@@ -94,6 +116,26 @@ public async Task<bool> SignInAsync()
94116
AuthStatusChanged?.Invoke(this, EventArgs.Empty);
95117
return false;
96118
}
119+
finally
120+
{
121+
if (loginBackend is not null)
122+
{
123+
try
124+
{
125+
loginBackend.OnLogin -= BackgroundApiOnOnLogin;
126+
await loginBackend.Stop();
127+
loginBackend.Dispose();
128+
}
129+
catch (Exception ex)
130+
{
131+
Logger.Warn(ex);
132+
}
133+
finally
134+
{
135+
loginBackend = null;
136+
}
137+
}
138+
}
97139
}
98140

99141
private string? codeFromAPI;
@@ -103,6 +145,18 @@ private void BackgroundApiOnOnLogin(object? sender, string c)
103145
codeFromAPI = c;
104146
}
105147

148+
private bool HasConfiguredOAuthClient()
149+
{
150+
return !string.IsNullOrWhiteSpace(GitHubClientId)
151+
&& !string.IsNullOrWhiteSpace(GitHubClientSecret)
152+
&& !string.Equals(GitHubClientId, MissingClientId, StringComparison.Ordinal)
153+
&& !string.Equals(
154+
GitHubClientSecret,
155+
MissingClientSecret,
156+
StringComparison.Ordinal
157+
);
158+
}
159+
106160
private async Task<bool> _completeSignInAsync(string code)
107161
{
108162
try

src/UniGetUI/Services/UserAvatar.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ private async Task _loginButton_Click()
6868
return;
6969
}
7070

71-
await client.SignInAsync();
71+
bool success = await client.SignInAsync();
72+
if (!success)
73+
{
74+
DialogHelper.ShowDismissableBalloon(
75+
CoreTools.Translate("Failed"),
76+
CoreTools.Translate("An error occurred while logging in: ")
77+
);
78+
}
7279
}
7380
catch (Exception ex)
7481
{
@@ -132,7 +139,7 @@ private PointButton GenerateLoginControl()
132139
FontSize = 12,
133140
};
134141
hyperlinkButton.Click += (_, _) =>
135-
MainApp.Instance.MainWindow.NavigationPage.ShowHelp("cloud-backup-overview/");
142+
CoreTools.Launch("https://devolutions.net/unigetui");
136143

137144
var loginButton = new PointButton
138145
{
@@ -235,7 +242,7 @@ private async Task<PointButton> GenerateLogoutControl()
235242
FontSize = 12,
236243
};
237244
hyperlinkButton.Click += (_, _) =>
238-
MainApp.Instance.MainWindow.NavigationPage.ShowHelp("cloud-backup-overview/");
245+
CoreTools.Launch("https://devolutions.net/unigetui");
239246

240247
var hyperlinkButton2 = new HyperlinkButton
241248
{

src/UniGetUI/Services/generate-secrets.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ if (-not (Test-Path -Path "Generated Files")) {
1212
}
1313

1414

15-
$clientId = $env:GH_UGUI_CLIENT_ID
16-
$clientSecret = $env:GH_UGUI_CLIENT_SECRET
15+
$clientId = $env:UNIGETUI_GITHUB_CLIENT_ID
16+
$clientSecret = $env:UNIGETUI_GITHUB_CLIENT_SECRET
1717

1818
if (-not $clientId) { $clientId = "CLIENT_ID_UNSET" }
1919
if (-not $clientSecret) { $clientSecret = "CLIENT_SECRET_UNSET" }
2020

2121
@"
22-
// Auto-generated file - do not modidy
22+
// Auto-generated file - do not modify
2323
namespace UniGetUI.Services
2424
{
2525
internal static partial class Secrets
@@ -29,4 +29,4 @@ namespace UniGetUI.Services
2929
}
3030
}
3131
"@ | Set-Content -Encoding UTF8 "Generated Files\Secrets.Generated.cs"
32-
cp "Generated Files\Secrets.Generated.cs" "$OutputPath\Generated Files\Secrets.Generated.cs"
32+
Copy-Item "Generated Files\Secrets.Generated.cs" "$OutputPath\Generated Files\Secrets.Generated.cs"

0 commit comments

Comments
 (0)