From da2cbea9301eb02886ccbd4f207342a9443a7e64 Mon Sep 17 00:00:00 2001 From: Fergal Reilly <5765633+ObsidianPhoenix@users.noreply.github.com> Date: Fri, 19 Sep 2025 12:01:24 +0100 Subject: [PATCH 1/4] Add SetupUrl to the SetupCode class --- ...RCodeTest.cs => QRCodeAndSetupUrlTests.cs} | 23 +++++++++++++++---- Google.Authenticator/SetupCode.cs | 8 ++++++- .../TwoFactorAuthenticator.cs | 3 ++- 3 files changed, 28 insertions(+), 6 deletions(-) rename Google.Authenticator.Tests/{QRCodeTest.cs => QRCodeAndSetupUrlTests.cs} (79%) diff --git a/Google.Authenticator.Tests/QRCodeTest.cs b/Google.Authenticator.Tests/QRCodeAndSetupUrlTests.cs similarity index 79% rename from Google.Authenticator.Tests/QRCodeTest.cs rename to Google.Authenticator.Tests/QRCodeAndSetupUrlTests.cs index 1fa7fa7..95d23b0 100644 --- a/Google.Authenticator.Tests/QRCodeTest.cs +++ b/Google.Authenticator.Tests/QRCodeAndSetupUrlTests.cs @@ -8,7 +8,7 @@ namespace Google.Authenticator.Tests { - public class QRCodeTest + public class QRCodeAndSetupUrlTests { [Theory] [InlineData("issuer", "otpauth://totp/issuer:a%40b.com?secret=ONSWG4TFOQ&issuer=issuer")] @@ -25,8 +25,13 @@ public void CanGenerateQRCode(string issuer, string expectedUrl) 2); var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl); + var rawUrl = setupCodeInfo.SetupUrl; - actualUrl.ShouldBe(expectedUrl); + Assert.Multiple(() => + { + actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected"); + rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected"); + }); } [Theory] @@ -44,8 +49,13 @@ public void CanGenerateSHA256QRCode(string issuer, string expectedUrl) 2); var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl); + var rawUrl = setupCodeInfo.SetupUrl; - actualUrl.ShouldBe(expectedUrl); + Assert.Multiple(() => + { + actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected"); + rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected"); + }); } [Theory] @@ -63,8 +73,13 @@ public void CanGenerateSHA512QRCode(string issuer, string expectedUrl) 2); var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl); + var rawUrl = setupCodeInfo.SetupUrl; - actualUrl.ShouldBe(expectedUrl); + Assert.Multiple(() => + { + actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected"); + rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected"); + }); } private static string ExtractUrlFromQRImage(string qrCodeSetupImageUrl) diff --git a/Google.Authenticator/SetupCode.cs b/Google.Authenticator/SetupCode.cs index 7964d14..ad90cab 100644 --- a/Google.Authenticator/SetupCode.cs +++ b/Google.Authenticator/SetupCode.cs @@ -9,13 +9,19 @@ public class SetupCode /// public string QrCodeSetupImageUrl { get; internal set; } + /// + /// The Raw otp:// url + /// + public string SetupUrl { get; internal set; } + public SetupCode() { } - public SetupCode(string account, string manualEntryKey, string qrCodeSetupImageUrl) + public SetupCode(string account, string manualEntryKey, string qrCodeSetupImageUrl, string setupUrl) { Account = account; ManualEntryKey = manualEntryKey; QrCodeSetupImageUrl = qrCodeSetupImageUrl; + SetupUrl = setupUrl; } } } \ No newline at end of file diff --git a/Google.Authenticator/TwoFactorAuthenticator.cs b/Google.Authenticator/TwoFactorAuthenticator.cs index 50dbb24..1060387 100644 --- a/Google.Authenticator/TwoFactorAuthenticator.cs +++ b/Google.Authenticator/TwoFactorAuthenticator.cs @@ -98,7 +98,8 @@ public SetupCode GenerateSetupCode(string issuer, return new SetupCode( accountTitleNoSpaces, encodedSecretKey.Trim('='), - generateQrCode ? GenerateQrCodeUrl(qrPixelsPerModule, provisionUrl) : ""); + generateQrCode ? GenerateQrCodeUrl(qrPixelsPerModule, provisionUrl) : "", + provisionUrl); } private static string GenerateQrCodeUrl(int qrPixelsPerModule, string provisionUrl) From 257e3acf11e807d39d7d3ae73c48821994aa9ad2 Mon Sep 17 00:00:00 2001 From: Fergal Reilly <5765633+ObsidianPhoenix@users.noreply.github.com> Date: Mon, 22 Sep 2025 09:11:53 +0100 Subject: [PATCH 2/4] Added UseDotNet@2 as a task to install dotnet 6 --- build/azure-pipeline.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build/azure-pipeline.yaml b/build/azure-pipeline.yaml index c3b75c8..a909c89 100644 --- a/build/azure-pipeline.yaml +++ b/build/azure-pipeline.yaml @@ -35,6 +35,13 @@ jobs: - script: dotnet build ./Google.Authenticator.Tests/Google.Authenticator.Tests.csproj --configuration $(buildConfiguration) --no-restore --no-dependencies displayName: build tests + - task: UseDotNet@2 + displayName: Use .NET Core SDK + inputs: + packageType: sdk + version: 6.x + installationPath: $(Agent.ToolsDirectory)/dotnet + - task: DotNetCoreCLI@2 displayName: test inputs: From 263f263de8289ab48dccb85b89a6b1e1e27e0eba Mon Sep 17 00:00:00 2001 From: Fergal Reilly <5765633+ObsidianPhoenix@users.noreply.github.com> Date: Mon, 22 Sep 2025 09:21:23 +0100 Subject: [PATCH 3/4] Upreved to dotnet 7 in the task --- build/azure-pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/azure-pipeline.yaml b/build/azure-pipeline.yaml index a909c89..7eabf30 100644 --- a/build/azure-pipeline.yaml +++ b/build/azure-pipeline.yaml @@ -39,7 +39,7 @@ jobs: displayName: Use .NET Core SDK inputs: packageType: sdk - version: 6.x + version: 7.x installationPath: $(Agent.ToolsDirectory)/dotnet - task: DotNetCoreCLI@2 From 9e16c3894e1baa1c63f4ec27e04cb1e37280e138 Mon Sep 17 00:00:00 2001 From: Fergal Reilly <5765633+ObsidianPhoenix@users.noreply.github.com> Date: Mon, 22 Sep 2025 09:29:22 +0100 Subject: [PATCH 4/4] We need both versions installed, not just one --- build/azure-pipeline.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/build/azure-pipeline.yaml b/build/azure-pipeline.yaml index 7eabf30..074a766 100644 --- a/build/azure-pipeline.yaml +++ b/build/azure-pipeline.yaml @@ -36,11 +36,16 @@ jobs: displayName: build tests - task: UseDotNet@2 - displayName: Use .NET Core SDK + displayName: Install dotnet 6 + inputs: + packageType: sdk + version: 6.x + + - task: UseDotNet@2 + displayName: Install dotnet 7 inputs: packageType: sdk version: 7.x - installationPath: $(Agent.ToolsDirectory)/dotnet - task: DotNetCoreCLI@2 displayName: test