Skip to content

Commit 7c47491

Browse files
authored
Merge pull request #254 from ObsidianPhoenix/features/253_Expose_otpAuth_Url
Add SetupUrl to the SetupCode class
2 parents a0a06da + 9e16c38 commit 7c47491

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

Google.Authenticator.Tests/QRCodeTest.cs renamed to Google.Authenticator.Tests/QRCodeAndSetupUrlTests.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Google.Authenticator.Tests
1010
{
11-
public class QRCodeTest
11+
public class QRCodeAndSetupUrlTests
1212
{
1313
[Theory]
1414
[InlineData("issuer", "otpauth://totp/issuer:a%40b.com?secret=ONSWG4TFOQ&issuer=issuer")]
@@ -25,8 +25,13 @@ public void CanGenerateQRCode(string issuer, string expectedUrl)
2525
2);
2626

2727
var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl);
28+
var rawUrl = setupCodeInfo.SetupUrl;
2829

29-
actualUrl.ShouldBe(expectedUrl);
30+
Assert.Multiple(() =>
31+
{
32+
actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected");
33+
rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected");
34+
});
3035
}
3136

3237
[Theory]
@@ -44,8 +49,13 @@ public void CanGenerateSHA256QRCode(string issuer, string expectedUrl)
4449
2);
4550

4651
var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl);
52+
var rawUrl = setupCodeInfo.SetupUrl;
4753

48-
actualUrl.ShouldBe(expectedUrl);
54+
Assert.Multiple(() =>
55+
{
56+
actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected");
57+
rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected");
58+
});
4959
}
5060

5161
[Theory]
@@ -63,8 +73,13 @@ public void CanGenerateSHA512QRCode(string issuer, string expectedUrl)
6373
2);
6474

6575
var actualUrl = ExtractUrlFromQRImage(setupCodeInfo.QrCodeSetupImageUrl);
76+
var rawUrl = setupCodeInfo.SetupUrl;
6677

67-
actualUrl.ShouldBe(expectedUrl);
78+
Assert.Multiple(() =>
79+
{
80+
actualUrl.ShouldBe(expectedUrl, "QR Code Url is not as expected");
81+
rawUrl.ShouldBe(expectedUrl, "SetupUrl is not as expected");
82+
});
6883
}
6984

7085
private static string ExtractUrlFromQRImage(string qrCodeSetupImageUrl)

Google.Authenticator/SetupCode.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ public class SetupCode
99
/// </summary>
1010
public string QrCodeSetupImageUrl { get; internal set; }
1111

12+
/// <summary>
13+
/// The Raw otp:// url
14+
/// </summary>
15+
public string SetupUrl { get; internal set; }
16+
1217
public SetupCode() { }
1318

14-
public SetupCode(string account, string manualEntryKey, string qrCodeSetupImageUrl)
19+
public SetupCode(string account, string manualEntryKey, string qrCodeSetupImageUrl, string setupUrl)
1520
{
1621
Account = account;
1722
ManualEntryKey = manualEntryKey;
1823
QrCodeSetupImageUrl = qrCodeSetupImageUrl;
24+
SetupUrl = setupUrl;
1925
}
2026
}
2127
}

Google.Authenticator/TwoFactorAuthenticator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public SetupCode GenerateSetupCode(string issuer,
9898
return new SetupCode(
9999
accountTitleNoSpaces,
100100
encodedSecretKey.Trim('='),
101-
generateQrCode ? GenerateQrCodeUrl(qrPixelsPerModule, provisionUrl) : "");
101+
generateQrCode ? GenerateQrCodeUrl(qrPixelsPerModule, provisionUrl) : "",
102+
provisionUrl);
102103
}
103104

104105
private static string GenerateQrCodeUrl(int qrPixelsPerModule, string provisionUrl)

build/azure-pipeline.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ jobs:
3535
- script: dotnet build ./Google.Authenticator.Tests/Google.Authenticator.Tests.csproj --configuration $(buildConfiguration) --no-restore --no-dependencies
3636
displayName: build tests
3737

38+
- task: UseDotNet@2
39+
displayName: Install dotnet 6
40+
inputs:
41+
packageType: sdk
42+
version: 6.x
43+
44+
- task: UseDotNet@2
45+
displayName: Install dotnet 7
46+
inputs:
47+
packageType: sdk
48+
version: 7.x
49+
3850
- task: DotNetCoreCLI@2
3951
displayName: test
4052
inputs:

0 commit comments

Comments
 (0)