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
## Configure a user secret for the provider's security key
46
+
## Configure a secret for the email provider's security key
47
+
48
+
Receive the email provider's security key from the provider and use it in the following guidance.
49
+
50
+
Use either or both of the following approaches to supply the secret to the app:
51
+
52
+
*[Secret Manager tool](#secret-manager-tool): The Secret Manager tool stores private data on the local machine and is only used during local development.
53
+
*[Azure Key Vault](#azure-key-vault): You can store the secret in a key vault for use in any environment, including for the Development environment when working locally. Some developers prefer to use key vaults for staging and production deployments and use the [Secret Manager tool](#secret-manager-tool) for local development.
54
+
55
+
We strongly recommend that you avoid storing secrets in project code or configuration files. Use secure authentication flows, such as either or both of the approaches in this section.
56
+
57
+
### Secret Manager tool
47
58
48
59
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.
49
60
@@ -63,6 +74,93 @@ For more information, see <xref:security/app-secrets>.
[Azure Key Vault](https://azure.microsoft.com/products/key-vault/) provides a safe approach for providing the app's client secret to the app.
80
+
81
+
To create a key vault and set a secret, see [About Azure Key Vault secrets (Azure documentation)](/azure/key-vault/secrets/about-secrets), which cross-links resources to get started with Azure Key Vault. To implement the code in this section, record the key vault URI and the secret name from Azure when you create the key vault and secret. When you set the access policy for the secret in the **Access policies** panel:
82
+
83
+
* Only the **Get** secret permission is required.
84
+
* Select the application as the **Principal** for the secret.
85
+
86
+
> [!IMPORTANT]
87
+
> A key vault secret is created with an expiration date. Be sure to track when a key vault secret is going to expire and create a new secret for the app prior to that date passing.
88
+
The following `GetKeyVaultSecret` method retrieves a secret from a key vault. Add this method to the server project. Adjust the namespace (`BlazorSample.Helpers`) to match your project namespace scheme.
If you wish to control the environment where the preceding code operates, for example to avoid running the code locally because you've opted to use the [Secret Manager tool](#secret-manager-tool) for local development, you can wrap the preceding code in a conditional statement that checks the environment:
135
+
136
+
```csharp
137
+
if (!context.HostingEnvironment.IsDevelopment())
138
+
{
139
+
...
140
+
}
141
+
```
142
+
143
+
In the `AzureAd` section of `appsettings.json`, add the following `VaultUri` and `SecretName` configuration keys and values:
144
+
145
+
```json
146
+
"VaultUri": "{VAULT URI}",
147
+
"SecretName": "{SECRET NAME}"
148
+
```
149
+
150
+
In the preceding example:
151
+
152
+
* The `{VAULT URI}` placeholder is the key vault URI. Include the trailing slash on the URI.
153
+
* The `{SECRET NAME}` placeholder is the secret name.
154
+
155
+
Example:
156
+
157
+
```json
158
+
"VaultUri": "https://contoso.vault.azure.net/",
159
+
"SecretName": "BlazorWebAppEntra"
160
+
```
161
+
162
+
Configuration is used to facilitate supplying dedicated key vaults and secret names based on the app's environmental configuration files. For example, you can supply different configuration values for `appsettings.Development.json` in development, `appsettings.Staging.json` when staging, and `appsettings.Production.json` for the production deployment. For more information, see <xref:blazor/fundamentals/configuration>.
163
+
66
164
## Implement `IEmailSender`
67
165
68
166
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.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/security/webassembly/standalone-with-identity/account-confirmation-and-password-recovery.md
+99-1Lines changed: 99 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,18 @@ Register the `AuthMessageSenderOptions` configuration instance in the server pro
## Configure a user secret for the provider's security key
53
+
## Configure a secret for the email provider's security key
54
+
55
+
Receive the email provider's security key from the provider and use it in the following guidance.
56
+
57
+
Use either or both of the following approaches to supply the secret to the app:
58
+
59
+
*[Secret Manager tool](#secret-manager-tool): The Secret Manager tool stores private data on the local machine and is only used during local development.
60
+
*[Azure Key Vault](#azure-key-vault): You can store the secret in a key vault for use in any environment, including for the Development environment when working locally. Some developers prefer to use key vaults for staging and production deployments and use the [Secret Manager tool](#secret-manager-tool) for local development.
61
+
62
+
We strongly recommend that you avoid storing secrets in project code or configuration files. Use secure authentication flows, such as either or both of the approaches in this section.
63
+
64
+
## Secret Manager Tool
54
65
55
66
If the server project has already been initialized for the [Secret Manager tool](xref:security/app-secrets), it will already have a 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 server project's directory. In Visual Studio, you can use the Developer PowerShell command prompt (use the `cd` command to change the directory to the server project after you open the command shell).
56
67
@@ -70,6 +81,93 @@ For more information, see <xref:security/app-secrets>.
[Azure Key Vault](https://azure.microsoft.com/products/key-vault/) provides a safe approach for providing the app's client secret to the app.
87
+
88
+
To create a key vault and set a secret, see [About Azure Key Vault secrets (Azure documentation)](/azure/key-vault/secrets/about-secrets), which cross-links resources to get started with Azure Key Vault. To implement the code in this section, record the key vault URI and the secret name from Azure when you create the key vault and secret. When you set the access policy for the secret in the **Access policies** panel:
89
+
90
+
* Only the **Get** secret permission is required.
91
+
* Select the application as the **Principal** for the secret.
92
+
93
+
> [!IMPORTANT]
94
+
> A key vault secret is created with an expiration date. Be sure to track when a key vault secret is going to expire and create a new secret for the app prior to that date passing.
95
+
The following `GetKeyVaultSecret` method retrieves a secret from a key vault. Add this method to the server project. Adjust the namespace (`BlazorSample.Helpers`) to match your project namespace scheme.
If you wish to control the environment where the preceding code operates, for example to avoid running the code locally because you've opted to use the [Secret Manager tool](#secret-manager-tool) for local development, you can wrap the preceding code in a conditional statement that checks the environment:
142
+
143
+
```csharp
144
+
if (!context.HostingEnvironment.IsDevelopment())
145
+
{
146
+
...
147
+
}
148
+
```
149
+
150
+
In the `AzureAd` section of `appsettings.json`, add the following `VaultUri` and `SecretName` configuration keys and values:
151
+
152
+
```json
153
+
"VaultUri": "{VAULT URI}",
154
+
"SecretName": "{SECRET NAME}"
155
+
```
156
+
157
+
In the preceding example:
158
+
159
+
* The `{VAULT URI}` placeholder is the key vault URI. Include the trailing slash on the URI.
160
+
* The `{SECRET NAME}` placeholder is the secret name.
161
+
162
+
Example:
163
+
164
+
```json
165
+
"VaultUri": "https://contoso.vault.azure.net/",
166
+
"SecretName": "BlazorWebAppEntra"
167
+
```
168
+
169
+
Configuration is used to facilitate supplying dedicated key vaults and secret names based on the app's environmental configuration files. For example, you can supply different configuration values for `appsettings.Development.json` in development, `appsettings.Staging.json` when staging, and `appsettings.Production.json` for the production deployment. For more information, see <xref:blazor/fundamentals/configuration>.
170
+
73
171
## Implement `IEmailSender` in the server project
74
172
75
173
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.
0 commit comments