Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/net6 workaround #102

Merged
merged 3 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net452;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net452;net5.0;net6.0</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
5 changes: 4 additions & 1 deletion Google.Authenticator/Google.Authenticator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net45;net5.0;net6.0</TargetFrameworks>
<Product>Google Authenticator Two-Factor</Product>
<Title>Google Authenticator Two-Factor Authentication Library</Title>
<Description>Google Authenticator Two-Factor Authentication Library (Not officially affiliated with Google.)</Description>
Expand Down Expand Up @@ -35,6 +35,9 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5'">
<DefineConstants>NET5_0;NETCOREAPP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6'">
<DefineConstants>NET6_0;</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>
Expand Down
25 changes: 17 additions & 8 deletions Google.Authenticator/TwoFactorAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,24 @@ private static string GenerateQrCodeUrl(int qrPixelsPerModule, string provisionU
var qrCodeUrl = "";
try
{
using (var qrGenerator = new QRCodeGenerator())
using (var qrGenerator = new QRCodeGenerator())
using (var qrCodeData = qrGenerator.CreateQrCode(provisionUrl, QRCodeGenerator.ECCLevel.Q))
using (var qrCode = new QRCode(qrCodeData))
using (var qrCodeImage = qrCode.GetGraphic(qrPixelsPerModule))
using (var ms = new MemoryStream())
{
qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
qrCodeUrl = $"data:image/png;base64,{Convert.ToBase64String(ms.ToArray())}";
}
#if NET6_0
using (var qrCode = new PngByteQRCode(qrCodeData))
{
var qrCodeImage = qrCode.GetGraphic(qrPixelsPerModule);
qrCodeUrl = $"data:image/png;base64,{Convert.ToBase64String(qrCodeImage)}";
}
#else
using (var qrCode = new QRCode(qrCodeData))
using (var qrCodeImage = qrCode.GetGraphic(qrPixelsPerModule))
using (var ms = new MemoryStream())
{
qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
qrCodeUrl = $"data:image/png;base64,{Convert.ToBase64String(ms.ToArray())}";
}
#endif

}
catch (TypeInitializationException e)
{
Expand Down