diff --git a/Server/Components/Account/Pages/Manage/EnableAuthenticator.razor b/Server/Components/Account/Pages/Manage/EnableAuthenticator.razor index c42f79522..90e33a873 100644 --- a/Server/Components/Account/Pages/Manage/EnableAuthenticator.razor +++ b/Server/Components/Account/Pages/Manage/EnableAuthenticator.razor @@ -6,6 +6,8 @@ @using System.Text.Encodings.Web @using Microsoft.AspNetCore.Identity @using Remotely.Server.Data +@using QRCoder; +@using QRCoder.Extensions; @inject UserManager UserManager @inject IdentityUserAccessor UserAccessor @@ -38,8 +40,16 @@ else
  • Scan the QR Code or enter this key @sharedKey into your two factor authenticator app. Spaces and casing do not matter.

    - -
    +
    + @if (!string.IsNullOrWhiteSpace(_qrCodeDataUri)) + { + QR code + } + else + { +
    Failed to generate QR code.
    + } +
  • @@ -73,6 +83,7 @@ else private RemotelyUser user = default!; private string? sharedKey; private string? authenticatorUri; + private string? _qrCodeDataUri; private IEnumerable? recoveryCodes; [CascadingParameter] @@ -132,6 +143,23 @@ else var email = await UserManager.GetEmailAsync(user); authenticatorUri = GenerateQrCodeUri(email!, unformattedKey!); + _qrCodeDataUri = GetQrCodeDataUri(authenticatorUri); + } + + private string? GetQrCodeDataUri(string authenticatorUri) + { + try + { + var qrCodeBytes = PngByteQRCodeHelper.GetQRCode(authenticatorUri, QRCodeGenerator.ECCLevel.Q, 5); + var base64QrCode = Convert.ToBase64String(qrCodeBytes); + return $"data:image/png;base64,{base64QrCode}"; + } + catch (Exception ex) + { + Logger.LogError(ex, "Error generating QR code"); + return null; + } + } private string FormatKey(string unformattedKey) @@ -156,7 +184,7 @@ else return string.Format( CultureInfo.InvariantCulture, AuthenticatorUriFormat, - UrlEncoder.Encode("Microsoft.AspNetCore.Identity.UI"), + UrlEncoder.Encode("Remotely"), UrlEncoder.Encode(email), unformattedKey); } diff --git a/Server/Components/Pages/Credits.razor b/Server/Components/Pages/Credits.razor index 9e298e4f9..5db7e1e1c 100644 --- a/Server/Components/Pages/Credits.razor +++ b/Server/Components/Pages/Credits.razor @@ -11,49 +11,6 @@
    - - - - - - -
    Bootswatch (Bootstrap Themes)
    - -
    NAudio
    +