<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unable to get successful EnableTwoFactor using dotnet client]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm using FusionAuth 1.21.0, and my app is running on .NET 5/Blazor Server.</p>
<p dir="auto">I am unable to get a successful response to EnableTwoFactor using the FusionAuth dotnet client.</p>
<p dir="auto">The first thing I do is GenerateTwoFactorSecret, which I use to create the QR code (using the GoogleAuthenticator NuGet Package by Brandon Potter).  The QR code is brought into the authenticator app and I get a code.  I validate the code with the QR code package's check method and get a successful validation of the code.</p>
<p dir="auto">I then try to EnableTwoFactor using the code and the validationSecret (Base64 from GenerateTwoFactorSecret) and no matter what I do I get a 421 error.</p>
<p dir="auto">The FusionAuthSyncClient is created using the same settings used to generate the secret, so it won't be that.  In FusionAuth API settings I have enabled all (get, post, put, patch &amp; delete) temporarily to test for /api/user/two-factor.</p>
<p dir="auto">The server, desktop and mobile device are all time sync'd within a second of each other.</p>
<p dir="auto">Here's my code:</p>
<pre><code>    async Task GenerateQRCode()
    {
        InProgress = true;
        await Task.Delay(1);
        FusionAuthSyncClient client = new FusionAuthSyncClient(Configuration["FusionAuthApiKey"], Configuration["FusionAuthAuthority"], Configuration["FusionAuthTenantId"]);

        var secretResponse = client.GenerateTwoFactorSecret();

        if (secretResponse.WasSuccessful())
        {
            verificationSecret = secretResponse.successResponse.secret;

            TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
            var setupInfo = tfa.GenerateSetupCode(Configuration["Settings:AppName"], emailAddress, verificationSecret, false, 300);

            QRCodeStr = setupInfo.QrCodeSetupImageUrl;
            manualEntrySetupCode = setupInfo.ManualEntryKey;

            QRCodeGenerated = true;
        }
    }
</code></pre>
<p dir="auto">GenerateQRCode is called from the HTML form, and once QRCodeGenerated becomes true, then the QR code is displayed.</p>
<pre><code>    void Verify2FACode()
    {
        TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
        isCorrectPIN = tfa.ValidateTwoFactorPIN(verificationSecret, verificationCode);
        isPINChecked = true;

        if (isCorrectPIN)
        {
            Enable2FA();
        }
    }

</code></pre>
<p dir="auto">Once the QR code is displayed, and the user has entered the verification code, on submit Verify2FACode is called.  If not successful the form is redisplayed notifying that the code was incorrect.  If successfully validated, Verify2FACode calls Enable2FA.</p>
<pre><code>    void Enable2FA()
    {
        FusionAuthSyncClient client = new FusionAuthSyncClient(Configuration["FusionAuthApiKey"], Configuration["FusionAuthAuthority"], Configuration["FusionAuthTenantId"]);
        Guid guid = new Guid(userID);

        io.fusionauth.domain.api.TwoFactorRequest requestBody = new io.fusionauth.domain.api.TwoFactorRequest();
        requestBody.code = verificationCode;
        requestBody.delivery = io.fusionauth.domain.TwoFactorDelivery.None;
        requestBody.secret = verificationSecret;

        var response = client.EnableTwoFactor(guid, requestBody);
        // once this works, do some more stuff...
    }

</code></pre>
<p dir="auto">It's at this point in the code that I'm getting a 421 error.</p>
<p dir="auto">Here is a list of some of the in memory variables:</p>
<p dir="auto"><img src="/community/forum/assets/uploads/files/1606282686459-screen-shot-2020-11-25-at-16.06.08.png" alt="Screen Shot 2020-11-25 at 16.06.08.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">So you can see that all the variables in the responseBody match what is passed to it.</p>
<p dir="auto">Unfortunately FusionAuth doesn't give my any feedback as to what is wrong beyond the code being incorrect (in the docs).  It'd be nice if there was a way for me to see what it is expecting based on the secret passed to it.</p>
<p dir="auto">The only thing I can think of is that the QR code that is being displayed is resulting in an incorrect code and one that does not match what FusionAuth is expecting.  I will play with that tomorrow, but in the mean time if anyone has any other suggestions I'd be happy to hear them.</p>
<p dir="auto">Thanks<br />
Craig</p>
]]></description><link>https://fusionauth.io/community/forum/topic/599/unable-to-get-successful-enabletwofactor-using-dotnet-client</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Jul 2026 13:36:52 GMT</lastBuildDate><atom:link href="https://fusionauth.io/community/forum/topic/599.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Nov 2020 05:48:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unable to get successful EnableTwoFactor using dotnet client on Fri, 28 Apr 2023 06:46:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/368">@craig-hind</a> I would appreciate it if you could share with us your QRCoder code snippet that solves the problem. You could email it to me <a href="mailto:ying.morris@gmail.com" rel="nofollow ugc">ying.morris@gmail.com</a><br />
Thanking you in advance.</p>
]]></description><link>https://fusionauth.io/community/forum/post/6094</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/6094</guid><dc:creator><![CDATA[ying.morris]]></dc:creator><pubDate>Fri, 28 Apr 2023 06:46:46 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to get successful EnableTwoFactor using dotnet client on Fri, 07 Apr 2023 07:12:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/2114">@tsukhwani</a> said in <a href="/community/forum/post/5927">Unable to get successful EnableTwoFactor using dotnet client</a>:</p>
<blockquote>
<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> said in <a href="/community/forum/post/1815">Unable to get successful EnableTwoFactor using dotnet client </a>:</p>
<blockquote>
<p dir="auto">RFC 6238. H</p>
</blockquote>
<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> <a href="https://wordwipe.io" rel="nofollow ugc">word wipe</a> I am not able delete  two-factor for user.<br />
Please help.</p>
<p dir="auto">Below are the steps I am following using fusion auth client 1.43.0</p>
<ul>
<li>Generate otp using <strong>SendTwoFactorCodeForEnableDisableAsync</strong> method of fusion auth client. Note: using only email based otp method.</li>
</ul>
<p dir="auto">{<br />
"methodId": "XXXX",<br />
"userId": "00000000-0000-0000-0000-00000000XXXX"<br />
}</p>
<ul>
<li>Then with the above review code, I am trying to delete two factor for user using <strong>DisableTwoFactorAsync</strong>, I am getting 421 which means code is not valid. I am not sure what is going wrong. PLEASE HELP ITS URGENT.</li>
</ul>
</blockquote>
<p dir="auto">Thanks for all the help.</p>
]]></description><link>https://fusionauth.io/community/forum/post/6058</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/6058</guid><dc:creator><![CDATA[summercurrants]]></dc:creator><pubDate>Fri, 07 Apr 2023 07:12:24 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to get successful EnableTwoFactor using dotnet client on Thu, 09 Feb 2023 14:21:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> said in <a href="/community/forum/post/1815">Unable to get successful EnableTwoFactor using dotnet client</a>:</p>
<blockquote>
<p dir="auto">RFC 6238. H</p>
</blockquote>
<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a> I am not able delete  two-factor for user.<br />
Please help.</p>
<p dir="auto">Below are the steps I am following using fusion auth client 1.43.0</p>
<ul>
<li>Generate otp using <strong>SendTwoFactorCodeForEnableDisableAsync</strong> method of fusion auth client. Note: using only email based otp method.</li>
</ul>
<p dir="auto">{<br />
"methodId": "XXXX",<br />
"userId": "00000000-0000-0000-0000-00000000XXXX"<br />
}</p>
<ul>
<li>Then with the above review code, I am trying to delete two factor for user using <strong>DisableTwoFactorAsync</strong>, I am getting 421 which means code is not valid. I am not sure what is going wrong. PLEASE HELP ITS URGENT.</li>
</ul>
]]></description><link>https://fusionauth.io/community/forum/post/5927</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/5927</guid><dc:creator><![CDATA[tsukhwani]]></dc:creator><pubDate>Thu, 09 Feb 2023 14:21:23 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to get successful EnableTwoFactor using dotnet client on Mon, 30 Nov 2020 03:53:02 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/20">@dan</a></p>
]]></description><link>https://fusionauth.io/community/forum/post/1816</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1816</guid><dc:creator><![CDATA[craig.hind]]></dc:creator><pubDate>Mon, 30 Nov 2020 03:53:02 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to get successful EnableTwoFactor using dotnet client on Mon, 30 Nov 2020 03:38:09 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="mention plugin-mentions-user plugin-mentions-a" href="https://fusionauth.io/community/forum/uid/368">@craig-hind</a> , I'll update the documentation to specify that any TOTP generator used for this application should adhere to RFC 6238. Here's a PR: <a href="https://github.com/FusionAuth/fusionauth-site/pull/329" rel="nofollow ugc">https://github.com/FusionAuth/fusionauth-site/pull/329</a></p>
<blockquote>
<p dir="auto">It would be nice of course if when using the FusionAuth API call GenerateTwoFactorSecret that it would also send back an image that can be used in the authenticator app. That would ensure the correct QR code and eliminate the need for an additional package to generate the QR code.</p>
</blockquote>
<p dir="auto">I know we're overhauling MFA functionality soon; please feel free to file a bug or add a comment here with this suggestion: <a href="https://github.com/FusionAuth/fusionauth-issues/issues/960" rel="nofollow ugc">https://github.com/FusionAuth/fusionauth-issues/issues/960</a></p>
]]></description><link>https://fusionauth.io/community/forum/post/1815</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1815</guid><dc:creator><![CDATA[dan]]></dc:creator><pubDate>Mon, 30 Nov 2020 03:38:09 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to get successful EnableTwoFactor using dotnet client on Thu, 26 Nov 2020 04:57:13 GMT]]></title><description><![CDATA[<p dir="auto">UPDATE:</p>
<p dir="auto">That was what the problem was.  I switched from the GoogleAuthenticator NuGet package mentioned in my first post, and I am now using QRCoder, and that seems to have solved the problem.</p>
<p dir="auto">Regards<br />
Craig</p>
]]></description><link>https://fusionauth.io/community/forum/post/1796</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1796</guid><dc:creator><![CDATA[craig.hind]]></dc:creator><pubDate>Thu, 26 Nov 2020 04:57:13 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to get successful EnableTwoFactor using dotnet client on Thu, 26 Nov 2020 00:21:58 GMT]]></title><description><![CDATA[<p dir="auto">UPDATE:</p>
<p dir="auto">I've determined that the NuGet package mentioned above is giving me a different QR code than what FusionAuth would give me if I manually enabled two factor authentication using the same secret.</p>
<p dir="auto">I've also determined that FusionAuth bases their two factor authentication on TOTP as defined in RFC 6238, so I can only assume that the package I chose is using a different algorithm.  I've looked at a the documentation for the NuGet package and it does not mention what algorithm it is using.</p>
<p dir="auto">I'm going to switch to another QR code generator that does adhere to RFC 6238 and see if that fixes things.</p>
<p dir="auto">It would be nice of course if when using the FusionAuth API call GenerateTwoFactorSecret that it would also send back an image that can be used in the authenticator app.  That would ensure the correct QR code and eliminate the need for an additional package to generate the QR code.</p>
<p dir="auto">I will update later with my findings.</p>
<ul>
<li>Craig</li>
</ul>
]]></description><link>https://fusionauth.io/community/forum/post/1795</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/1795</guid><dc:creator><![CDATA[craig.hind]]></dc:creator><pubDate>Thu, 26 Nov 2020 00:21:58 GMT</pubDate></item></channel></rss>