2FA QR code is not generating in Blazor Web app.

Diwakar Devangam 55 Reputation points
2023-11-16T06:15:23.6533333+00:00

using Blazor Web App template and authentication type as individual accounts, 2FA is not generating the QR code. Is this need to be fixed?

Microsoft Authenticator
Microsoft Authenticator
A Microsoft app for iOS and Android devices that enables authentication with two-factor verification, phone sign-in, and code generation.
6,195 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,511 questions
{count} votes

Accepted answer
  1. Ruikai Feng - MSFT 2,556 Reputation points Microsoft Vendor
    2023-11-17T05:37:45.6533333+00:00

    Hi,@Diwakar Devangam

    You have to add the required js file/js codes yourself follow this document:

    Download the qrcode.js JavaScript library to the wwwroot\lib folder in your project.

    Create a new JavaScript file called qr.js in wwwroot/js and add the following code to generate the QR Code:

    window.addEventListener("load", () => {
      const uri = document.getElementById("qrCodeData").getAttribute('data-url');
      new QRCode(document.getElementById("qrCode"),
        {
          text: uri,
          width: 150,
          height: 150
        });
    });
    

    Refer the required js file in EnableAuthenticator.cshtml:

    @section Scripts {
        @await Html.PartialAsync("_ValidationScriptsPartial")
    
        <script type="text/javascript" src="~/lib/qrcode.js"></script>
        <script type="text/javascript" src="~/js/qr.js"></script>
    }
    
    
    

    It works as expected on myside:

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the email notification for this thread.

    Best regards,

    Ruikai Feng

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful