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
Copy file name to clipboardExpand all lines: aspnetcore/blazor/security/blazor-web-app-with-entra.md
+72Lines changed: 72 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,78 @@ The important changes to the `LogInOrOut` component are demonstrated in the foll
153
153
</div>
154
154
```
155
155
156
+
## Obtain the client secret from Azure Key Vault
157
+
158
+
[Azure Key Vault](https://azure.microsoft.com/products/key-vault/) provides a safe approach for providing the app's client secret to the app when hosting in [Microsoft Azure](https://azure.microsoft.com/).
159
+
160
+
To create a key vault and set a client 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.
161
+
162
+
The following `GetSecretFromKeyVault` method retrieves a secret from a key vault using the Entra tenant ID. Add this method to the server project. Adjust the namespace (`BlazorSample.Helpers`) to match your project namespace scheme.
In the server project's `Program` file after Microsoft identity platform services are added (`AddMicrosoftIdentityWebApp`), obtain and apply the client secret using the following code:
Supply the vault URI and secret name from configuration.
208
+
209
+
In the `AzureAd` section of `appsettings.json`, add configuration keys and values:
210
+
211
+
* The `{VAULT URI}` placeholder is the key vault URI. Include the trailing slash on the URI.
212
+
* The `{SECRET NAME}` placeholder is the secret name.
213
+
214
+
```json
215
+
"VaultUri": "{VAULT URI}",
216
+
"SecretName": "{SECRET NAME}"
217
+
```
218
+
219
+
Example:
220
+
221
+
```json
222
+
"VaultUri": "https://contoso.vault.azure.net/",
223
+
"SecretName": "BlazorSample_Entra"
224
+
```
225
+
226
+
Configuration is used to facilitate supplying values based on the app's environmental configuration files. For example, `appsettings.Development.json` for Development, `appsettings.Staging.json` for Staging, and `appsettings.Production.json` for Production can use dedicated key vaults for each environment.
0 commit comments