You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Initial plan
* Refresh identity-enable-qrcodes article per issue
Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/8632276a-efa4-4be5-8864-182179176818
Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
* Editorial fixes
* Update identity-enable-qrcodes.md
updated metadata to sorted by alpha
* Revise QR code generation notes for ASP.NET Core
Updated notes for QR code generation guidance, including Blazor-specific instructions for ASP.NET Core 8.0 or later.
* Add list per suggestion from tdykstra review
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Co-authored-by: wadepickett <wpickett@microsoft.com>
# Enable QR code generation for TOTP authenticator apps in ASP.NET Core
12
14
13
-
ASP.NET Core ships with support for authenticator applications for individual authentication. Two factor authentication (2FA) authenticator apps, using a Time-based One-time Password Algorithm (TOTP), are the industry recommended approach for 2FA. 2FA using TOTP is preferred to SMS 2FA. An authenticator app provides a 6 to 8 digit code which users must enter after confirming their username and password. Typically an authenticator app is installed on a smartphone.
15
+
ASP.NET Core includes support for authenticator applications for individual authentication:
16
+
17
+
- Two-factor authentication (2FA) authenticator apps use a Time-based One-time Password Algorithm (TOTP), the industry-recommended approach for 2FA.
18
+
- TOTP-based 2FA is preferred over SMS 2FA.
19
+
- An authenticator app provides a 6 to 8 digit code that users enter after confirming their username and password.
20
+
- Typically, users install an authenticator app on a smartphone.
14
21
15
22
> [!WARNING]
16
-
> An ASP.NET Core TOTP code should be kept secret because it can be used to authenticate successfully multiple times before it expires.
23
+
> Keep an ASP.NET Core TOTP code secret because it can be used to authenticate successfully multiple times before it expires.
17
24
18
25
:::moniker range=">= aspnetcore-8.0"
19
26
20
-
The ASP.NET Core web app templates support authenticators but don't provide support for QR code generation. QR code generators ease the setup of 2FA. This document provides guidance for Razor Pages and MVC apps on how to add [QR code](https://wikipedia.org/wiki/QR_code) generation to the 2FA configuration page. For guidance that applies to Blazor Web Apps, see <xref:blazor/security/qrcodes-for-authenticator-apps>. For guidance that applies to Blazor WebAssembly apps, see <xref:blazor/security/webassembly/standalone-with-identity/qrcodes-for-authenticator-apps>.
27
+
The ASP.NET Core web app templates support authenticators but don't provide support for QR code generation. QR code generators make it easier to set up 2FA. This article provides guidance for Razor Pages and MVC apps on how to add [QR code](https://wikipedia.org/wiki/QR_code) generation to the 2FA configuration page. For guidance that applies to Blazor Web Apps, see <xref:blazor/security/qrcodes-for-authenticator-apps>. For guidance that applies to Blazor WebAssembly apps, see <xref:blazor/security/webassembly/standalone-with-identity/qrcodes-for-authenticator-apps>.
21
28
22
29
:::moniker-end
23
30
24
31
:::moniker range="< aspnetcore-8.0"
25
32
26
-
The ASP.NET Core web app templates support authenticators but don't provide support for QR code generation. QR code generators ease the setup of 2FA. This document guides you through adding [QR code](https://wikipedia.org/wiki/QR_code) generation to the 2FA configuration page.
33
+
The ASP.NET Core web app templates support authenticators but don't provide support for QR code generation. QR code generators make it easier to set up 2FA. This article guides you through adding [QR code](https://wikipedia.org/wiki/QR_code) generation to the 2FA configuration page.
34
+
35
+
> [!NOTE]
36
+
> For ASP.NET Core 8.0 or later, Blazor-specific guidance for QR code generation is available for <xref:blazor/security/qrcodes-for-authenticator-apps> (Blazor Web App) and <xref:blazor/security/webassembly/standalone-with-identity/qrcodes-for-authenticator-apps> (Blazor WebAssembly with Identity).
27
37
28
38
:::moniker-end
29
39
30
-
Two-factor authentication does not happen using an external authentication provider, such as [Google](xref:security/authentication/google-logins) or [Facebook](xref:security/authentication/facebook-logins). External logins are protected by whatever mechanism the external login provider provides. Consider, for example, the [Microsoft](xref:security/authentication/microsoft-logins) authentication provider requires a hardware key or another 2FA approach. If the default templates required 2FA for both the web app and the external authentication provider, then users would be required to satisfy two 2FA approaches. Requiring two 2FA approaches deviates from established security practices, which typically rely on a single, strong 2FA method for authentication.
40
+
Two-factor authentication doesn't happen by using an external authentication provider, such as [Google](xref:security/authentication/google-logins) or [Facebook](xref:security/authentication/facebook-logins). External logins are protected by whatever mechanism the external login provider provides. For example, the [Microsoft](xref:security/authentication/microsoft-logins) authentication provider requires a hardware key or another 2FA approach. If the default templates required 2FA for both the web app and the external authentication provider, users would need to satisfy two 2FA approaches. Requiring two 2FA approaches deviates from established security practices, which typically rely on a single, strong 2FA method for authentication.
31
41
32
42
## Adding QR codes to the 2FA configuration page
33
43
34
-
These instructions use `qrcode.js` from the https://davidshimjs.github.io/qrcodejs/ repo.
44
+
These instructions use `qrcode.js` from the [https://davidshimjs.github.io/qrcodejs/](https://davidshimjs.github.io/qrcodejs/) repo.
35
45
36
46
* Download the [`qrcode.js` JavaScript library](https://davidshimjs.github.io/qrcodejs/) to the `wwwroot\lib` folder in your project.
37
47
* Follow the instructions in [Scaffold Identity](xref:security/authentication/scaffold-identity) to generate `/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml`.
38
48
* In `/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml`, locate the `Scripts` section at the end of the file:
* Delete the paragraph which links you to these instructions.
81
+
* Delete the paragraph that links you to these instructions.
72
82
73
-
Run your app and ensure that you can scan the QR code and validate the code the authenticator proves.
83
+
Run your app and ensure that you can scan the QR code and validate the code the authenticator provides.
74
84
75
85
## Change the site name in the QR code
76
86
77
-
The site name in the QR code is taken from the project name you choose when initially creating your project. You can change it by looking for the `GenerateQrCodeUri(string email, string unformattedKey)` method in the `/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs`.
87
+
The site name in the QR code comes from the project name you choose when initially creating your project. You can change it by looking for the `GenerateQrCodeUri(string email, string unformattedKey)` method in the `/Areas/Identity/Pages/Account/Manage/EnableAuthenticator.cshtml.cs`.
78
88
79
89
The default code from the template looks as follows:
The second parameter in the call to `string.Format` is your site name, taken from your solution name. It can be changed to any value, but it must always be URL encoded.
102
+
The second parameter in the call to `string.Format` is your site name, taken from your solution name. You can change it to any value, but it must always be URL encoded.
93
103
94
-
## Using a different QR Code library
104
+
## Using a different QR code library
95
105
96
-
You can replace the QR Code library with your preferred library. The HTML contains a `qrCode` element into which you can place a QR Code by whatever mechanism your library provides.
106
+
You can replace the QR code library with your preferred library. The HTML contains a `qrCode` element into which you can place a QR code by whatever mechanism your library provides.
97
107
98
-
The correctly formatted URL for the QR Code is available in the:
108
+
You can find the correctly formatted URL for the QR code in the:
99
109
100
110
*`AuthenticatorUri` property of the model.
101
111
*`data-url` property in the `qrCodeData` element.
102
112
103
113
## TOTP client and server time skew
104
114
105
-
TOTP (Time-based One-Time Password) authentication depends on both the server and authenticator device having an accurate time. Tokens only last for 30 seconds. If TOTP 2FA logins are failing, check that the server time is accurate, and preferably synchronized to an accurate NTP service.
115
+
TOTP (Time-based One-Time Password) authentication depends on both the server and authenticator device having an accurate time. Tokens only last for 30 seconds. If TOTP 2FA logins fail, check that the server time is accurate, and preferably synchronized to an accurate NTP service.
0 commit comments