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
* Blazor WebAssembly with ASP.NET Core Identity (<xref:blazor/security/webassembly/standalone-with-identity>)
192
+
* Blazor WebAssembly with ASP.NET Core Identity (<xref:blazor/security/webassembly/standalone-with-identity/index>)
193
193
* .NET MAUI Blazor Hybrid app with a Blazor Web App and a shared UI provided by a Razor class library (RCL) (<xref:blazor/hybrid/tutorials/maui-blazor-web-app>)
# Account confirmation and password recovery in ASP.NET Core Blazor
11
11
12
12
This article explains how to configure an ASP.NET Core Blazor Web App with email confirmation and password recovery.
13
13
14
+
> [!NOTE]
15
+
> This article only applies to Blazor Web Apps. To implement email confirmation and password recovery for standalone Blazor WebAssembly apps with ASP.NET Core Identity, see <xref:blazor/security/webassembly/standalone-with-identity/account-confirmation-and-password-recovery>.
16
+
14
17
## Namespace
15
18
16
19
The app's namespace used by the example in this article is `BlazorSample`. Update the code examples to use the namespace of your app.
@@ -21,7 +24,7 @@ In this article, [Mailchimp's Transactional API](https://mailchimp.com/developer
21
24
22
25
Create a class to fetch the secure email API key. The example in this article uses a class named `AuthMessageSenderOptions` with a `EmailAuthKey` property to hold the key.
## Configure a user secret for the provider's security key
42
45
43
-
Set the key with the [Secret Manager tool](xref:security/app-secrets). In the following example, the key name is `EmailAuthKey`, and the key is represented by the `{KEY}` placeholder. In a command shell, navigate to the app's root folder and execute the following command with the API key:
46
+
If the project has already been initialized for the [Secret Manager tool](xref:security/app-secrets), it will already have an app secrets identifier (`<AppSecretsId>`) in its project file (`.csproj`). In Visual Studio, you can tell if the app secrets ID is present by looking at the **Properties** panel when the project is selected in **Solution Explorer**. If the app hasn't been initialized, execute the following command in a command shell opened to the project's directory. In Visual Studio, you can use the Developer PowerShell command prompt.
47
+
48
+
```dotnetcli
49
+
dotnet user-secrets init
50
+
```
51
+
52
+
Set the key with the Secret Manager tool. In the following example, the key name is `EmailAuthKey`, and the key is represented by the `{KEY}` placeholder. In a command shell, navigate to the app's root folder and execute the following command with the API key:
44
53
45
54
```dotnetcli
46
55
dotnet user-secrets set "EmailAuthKey" "{KEY}"
47
56
```
48
57
58
+
If using Visual Studio, you can confirm the secret is set by right-clicking the server project in **Solution Explorer** and selecting **Manage User Secrets**.
59
+
49
60
For more information, see <xref:security/app-secrets>.
Implement `IEmailSender` for the provider. The following example is based on Mailchimp's Transactional API using [Mandrill.net](https://www.nuget.org/packages/Mandrill.net). For a different provider, refer to their documentation on how to implement sending a message in the `Execute` method.
66
+
The following example is based on Mailchimp's Transactional API using [Mandrill.net](https://www.nuget.org/packages/Mandrill.net). For a different provider, refer to their documentation on how to implement sending an email message.
67
+
68
+
Add the [Mandrill.net](https://www.nuget.org/packages/Mandrill.net) NuGet package to the project.
69
+
70
+
Add the following `EmailSender` class to implement <xref:Microsoft.AspNetCore.Identity.IEmailSender>.
The builtin Identity user tokens ([AspNetCore/src/Identity/Extensions.Core/src/TokenOptions.cs](https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Extensions.Core/src/TokenOptions.cs)) have a [one day timeout](https://github.com/dotnet/AspNetCore/blob/main/src/Identity/Core/src/DataProtectionTokenProviderOptions.cs).
188
+
The built-in Identity user tokens ([AspNetCore/src/Identity/Extensions.Core/src/TokenOptions.cs](https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Extensions.Core/src/TokenOptions.cs)) have a [one day timeout](https://github.com/dotnet/AspNetCore/blob/main/src/Identity/Core/src/DataProtectionTokenProviderOptions.cs).
## Enable account confirmation after a site has users
275
+
276
+
Enabling account confirmation on a site with users locks out all the existing users. Existing users are locked out because their accounts aren't confirmed. To work around existing user lockout, use one of the following approaches:
277
+
278
+
* Update the database to mark all existing users as confirmed.
279
+
* Confirm existing users. For example, batch-send emails with confirmation links.
280
+
259
281
## Troubleshoot
260
282
261
283
If you can't get email working:
@@ -267,16 +289,6 @@ If you can't get email working:
267
289
* Try another email alias on a different email provider, such as Microsoft, Yahoo, or Gmail.
268
290
* Try sending to different email accounts.
269
291
270
-
> [!WARNING]
271
-
> Do **not** use production secrets in test and development. If you publish the app to Azure, set secrets as application settings in the Azure Web App portal. The configuration system is set up to read keys from environment variables.
272
-
273
-
## Enable account confirmation after a site has users
274
-
275
-
Enabling account confirmation on a site with users locks out all the existing users. Existing users are locked out because their accounts aren't confirmed. To work around existing user lockout, use one of the following approaches:
276
-
277
-
* Update the database to mark all existing users as confirmed.
278
-
* Confirm existing users. For example, batch-send emails with confirmation links.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/security/authentication-state.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -474,7 +474,7 @@ The following component's `SignIn` method creates a claims principal for the use
474
474
*[Server-side unauthorized content display while prerendering with a custom `AuthenticationStateProvider`](xref:blazor/security/server/index#unauthorized-content-display-while-prerendering-with-a-custom-authenticationstateprovider)
475
475
*[How to access an `AuthenticationStateProvider` from a `DelegatingHandler` set up using an `IHttpClientFactory`](xref:blazor/security/server/additional-scenarios#access-authenticationstateprovider-in-outgoing-request-middleware)
@@ -483,7 +483,7 @@ The following component's `SignIn` method creates a claims principal for the use
483
483
*[Server-side unauthorized content display while prerendering with a custom `AuthenticationStateProvider`](xref:blazor/security/server/index#unauthorized-content-display-while-prerendering-with-a-custom-authenticationstateprovider)
484
484
*[How to access an `AuthenticationStateProvider` from a `DelegatingHandler` set up using an `IHttpClientFactory`](xref:blazor/security/server/additional-scenarios#access-authenticationstateprovider-in-outgoing-request-middleware)
[Prerendering with authentication in hosted Blazor WebAssembly apps](xref:blazor/security/webassembly/additional-scenarios#prerendering-with-authentication)
0 commit comments