Use AuthenticatorUrl generated on the server in EnableAuthenticator pages

This commit is contained in:
Pranav K 2018-01-11 15:13:31 -08:00
parent 435ab653db
commit ce88212f49
2 changed files with 7 additions and 9 deletions

View File

@ -24,7 +24,7 @@
<p>Scan the QR Code or enter this key <kbd>@Model.SharedKey</kbd> into your two factor authenticator app. Spaces and casing do not matter.</p> <p>Scan the QR Code or enter this key <kbd>@Model.SharedKey</kbd> into your two factor authenticator app. Spaces and casing do not matter.</p>
<div class="alert alert-info">To enable QR code generation please read our <a href="https://go.microsoft.com/fwlink/?Linkid=852423">documentation</a>.</div> <div class="alert alert-info">To enable QR code generation please read our <a href="https://go.microsoft.com/fwlink/?Linkid=852423">documentation</a>.</div>
<div id="qrCode"></div> <div id="qrCode"></div>
<div id="qrCodeData" data-url="@Html.Raw(Model.AuthenticatorUri)"></div> <div id="qrCodeData" data-url="@Model.AuthenticatorUri"></div>
</li> </li>
<li> <li>
<p> <p>

View File

@ -55,11 +55,6 @@ namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage
} }
await LoadSharedKeyAndQrCodeUriAsync(user); await LoadSharedKeyAndQrCodeUriAsync(user);
if (string.IsNullOrEmpty(SharedKey))
{
await _userManager.ResetAuthenticatorKeyAsync(user);
await LoadSharedKeyAndQrCodeUriAsync(user);
}
return Page(); return Page();
} }
@ -100,11 +95,14 @@ namespace Microsoft.AspNetCore.Identity.UI.Pages.Account.Manage
{ {
// Load the authenticator key & QR code URI to display on the form // Load the authenticator key & QR code URI to display on the form
var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
if (!string.IsNullOrEmpty(unformattedKey)) if (string.IsNullOrEmpty(unformattedKey))
{ {
SharedKey = FormatKey(unformattedKey); await _userManager.ResetAuthenticatorKeyAsync(user);
AuthenticatorUri = GenerateQrCodeUri(user.Email, unformattedKey); unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
} }
SharedKey = FormatKey(unformattedKey);
AuthenticatorUri = GenerateQrCodeUri(user.Email, unformattedKey);
} }
private string FormatKey(string unformattedKey) private string FormatKey(string unformattedKey)