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

Diwakar Devangam 75 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?

Developer technologies .NET Blazor
Microsoft Security Microsoft Authenticator
{count} votes

Accepted answer
  1. Anonymous
    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.