Skip to content

Commit c2663b7

Browse files
committed
validation
1 parent 5d8bb3f commit c2663b7

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

articles/app-service/tutorial-connect-app-access-sql-database-as-user-dotnet.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This tutorial shows you how to enable [built-in authentication](overview-authent
1414
- Gives the back-end database (or any other Azure service) more control over who or how much to grant access to its data and functionality.
1515
- Lets the app tailor its data presentation to the signed-in user.
1616

17-
In this tutorial, you'll add Azure Active Directory authentication to the sample web app you deployed in one of the following tutorials:
17+
In this tutorial, you add Azure Active Directory authentication to the sample web app you deployed in one of the following tutorials:
1818

1919
- [Tutorial: Build an ASP.NET app in Azure with Azure SQL Database](app-service-web-tutorial-dotnet-sqldatabase.md)
2020
- [Tutorial: Build an ASP.NET Core and Azure SQL Database app in Azure App Service](tutorial-dotnetcore-sqldb-app.md)
@@ -85,7 +85,7 @@ First, enable Azure Active Directory authentication to SQL Database by assigning
8585
az sql server ad-only-auth enable --resource-group <group-name> --server-name <server-name>
8686
```
8787
88-
For more information on adding an Active Directory admin, see [Provision an Azure Active Directory administrator for your server](../azure-sql/database/authentication-aad-configure.md#provision-azure-ad-admin-sql-managed-instance)
88+
For more information on adding an Active Directory admin, see [Provision Azure AD admin (SQL Database)](/azure/azure-sql/database/authentication-aad-configure#provision-azure-ad-admin-sql-database).
8989
9090
## 2. Enable user authentication for your app
9191
@@ -112,7 +112,7 @@ Currently, your Azure app connects to SQL Database uses SQL authentication (user
112112
113113
1. In the **Authentication** page for the app, select your app name under **Identity provider**. This app registration was automatically generated for you. Select **API permissions** in the left menu.
114114
115-
1. Select **Add a permission**, then select **Apis my organization uses**.
115+
1. Select **Add a permission**, then select **APIs my organization uses**.
116116
117117
1. Type *Azure SQL Database* in the search box and select the result.
118118
@@ -132,7 +132,7 @@ authSettings=$(echo "$authSettings" | jq '.properties' | jq '.identityProviders.
132132
az webapp auth set --resource-group <group-name> --name <app-name> --body "$authSettings"
133133
```
134134

135-
The commands effectively add a `loginParameters` property with additional custom scopes. Here's an explanation of the requested scopes:
135+
The commands effectively add a `loginParameters` property with extra custom scopes. Here's an explanation of the requested scopes:
136136

137137
- `openid`, `profile`, and `email` are requested by App Service by default already. For information, see [OpenID Connect Scopes](../active-directory/develop/v2-permissions-and-consent.md#openid-connect-scopes).
138138
- `https://database.windows.net/user_impersonation` refers to Azure SQL Database. It's the scope that gives you a JWT token that includes SQL Database as a [token audience](https://wikipedia.org/wiki/JSON_Web_Token).
@@ -186,7 +186,7 @@ public MyDatabaseContext (DbContextOptions<MyDatabaseContext> options, IHttpCont
186186

187187
# [ASP.NET](#tab/dotnet)
188188

189-
1.**If you came from [Tutorial: Build an ASP.NET app in Azure with SQL Database](app-service-web-tutorial-dotnet-sqldatabase.md)**, you set a connection string in App Service using SQL authentication, with a username and password. Use the following command to remove the connection secrets, but replace *\<group-name>*, *\<app-name>*, *\<db-server-name>*, and *\<db-name>* with yours.
189+
1. **If you came from [Tutorial: Build an ASP.NET app in Azure with SQL Database](app-service-web-tutorial-dotnet-sqldatabase.md)**, you set a connection string in App Service using SQL authentication, with a username and password. Use the following command to remove the connection secrets, but replace *\<group-name>*, *\<app-name>*, *\<db-server-name>*, and *\<db-name>* with yours.
190190

191191
```azurecli-interactive
192192
az webapp config connection-string set --resource-group <group-name> --name <app-name> --type SQLAzure --settings MyDbConnection="server=tcp:<db-server-name>.database.windows.net;database=<db-name>;"
@@ -206,11 +206,11 @@ public MyDatabaseContext (DbContextOptions<MyDatabaseContext> options, IHttpCont
206206
az webapp config connection-string set --resource-group <group-name> --name <app-name> --type SQLAzure --settings defaultConnection="server=tcp:<db-server-name>.database.windows.net;database=<db-name>;"
207207
```
208208
209-
1. You would've made your code changes in your GitHub fork, with Visual Studio Code in the browser. From the left menue, select **Source Control**.
209+
1. You would have made your code changes in your GitHub fork, with Visual Studio Code in the browser. From the left menu, select **Source Control**.
210210
211211
1. Type in a commit message like `OBO connect` and select **Commit**.
212212
213-
The commit will trigger a deployment to App Service. Wait a few minutes for the deployment to finish.
213+
The commit triggers a GitHub Actions deployment to App Service. Wait a few minutes for the deployment to finish.
214214
215215
-----
216216
@@ -222,24 +222,25 @@ You should now be able to edit the to-do list as before.
222222
223223
[!INCLUDE [cli-samples-clean-up](../../includes/cli-samples-clean-up.md)]
224224
225-
## FAQ
225+
## Frequently asked questions
226226
227-
- [Why do I get a `Login failed for user '<token-identified principal>'.` error?]()
228-
- [How do I add other Azure AD users or groups in Azure SQL Database?]()
229-
- [How do I debug locally when using App Service authentication?]()
227+
- [Why do I get a `Login failed for user '<token-identified principal>'.` error?](#why-do-i-get-a-login-failed-for-user-token-identified-principal-error)
228+
- [How do I add other Azure AD users or groups in Azure SQL Database?](#how-do-i-add-other-azure-ad-users-or-groups-in-azure-sql-database)
229+
- [How do I debug locally when using App Service authentication?](#how-do-i-debug-locally-when-using-app-service-authentication)
230+
- [What happens when access tokens expire?](#what-happens-when-access-tokens-expire)
230231
231232
#### Why do I get a `Login failed for user '<token-identified principal>'.` error?
232233
233234
The most common causes of this error are:
234235
235-
- You're running the code locally, and there's no valid token in the `X-MS-TOKEN-AAD-ACCESS-TOKEN` request header. See [How do I debug locally when using App Service authentication?]().
236+
- You're running the code locally, and there's no valid token in the `X-MS-TOKEN-AAD-ACCESS-TOKEN` request header. See [How do I debug locally when using App Service authentication?](#how-do-i-debug-locally-when-using-app-service-authentication).
236237
- Azure AD authentication isn't configured on your SQL Database.
237-
- The signed-in user isn't permitted to connect to the database. See [How do I add other Azure AD users or groups in Azure SQL Database?]().
238+
- The signed-in user isn't permitted to connect to the database. See [How do I add other Azure AD users or groups in Azure SQL Database?](#how-do-i-add-other-azure-ad-users-or-groups-in-azure-sql-database).
238239
239240
#### How do I add other Azure AD users or groups in Azure SQL Database?
240241
241-
1. Connect to your database server, such as with [sqlcmd](../azure-sql/database/authentication-aad-configure.md#sqlcmd) or [SSMS](../azure-sql/database/authentication-aad-configure.md#connect-to-the-database-using-ssms-or-ssdt).
242-
1. [Create contained users mapped to Azure AD identities](../azure-sql/database/authentication-aad-configure.md#create-contained-users-mapped-to-azure-ad-identities) in SQL Database documentation.
242+
1. Connect to your database server, such as with [sqlcmd](/azure/azure-sql/database/authentication-aad-configure#sqlcmd) or [SSMS](/azure/azure-sql/database/authentication-aad-configure#connect-to-the-database-using-ssms-or-ssdt).
243+
1. [Create contained users mapped to Azure AD identities](/azure/azure-sql/database/authentication-aad-configure#create-contained-users-mapped-to-azure-ad-identities) in SQL Database documentation.
243244
244245
The following Transact-SQL example adds an Azure AD identity to SQL Server and gives it some database roles:
245246

articles/app-service/tutorial-connect-msi-sql-database.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.custom: "devx-track-csharp, mvc, cli-validate, devx-track-azurecli"
99
---
1010
# Tutorial: Connect to SQL Database from .NET App Service without secrets using a managed identity
1111

12-
[App Service](overview.md) provides a highly scalable, self-patching web hosting service in Azure. It also provides a [managed identity](overview-managed-identity.md) for your app, which is a turn-key solution for securing access to [Azure SQL Database](/azure/sql-database/) and other Azure services. Managed identities in App Service make your app more secure by eliminating secrets from your app, such as credentials in the connection strings. In this tutorial, you'll add managed identity to the sample web app you built in one of the following tutorials:
12+
[App Service](overview.md) provides a highly scalable, self-patching web hosting service in Azure. It also provides a [managed identity](overview-managed-identity.md) for your app, which is a turn-key solution for securing access to [Azure SQL Database](/azure/sql-database/) and other Azure services. Managed identities in App Service make your app more secure by eliminating secrets from your app, such as credentials in the connection strings. In this tutorial, you add managed identity to the sample web app you built in one of the following tutorials:
1313

1414
- [Tutorial: Build an ASP.NET app in Azure with Azure SQL Database](app-service-web-tutorial-dotnet-sqldatabase.md)
1515
- [Tutorial: Build an ASP.NET Core and Azure SQL Database app in Azure App Service](tutorial-dotnetcore-sqldb-app.md)
@@ -156,11 +156,11 @@ The steps you follow for your project depends on whether you're using [Entity Fr
156156
conn.AccessToken = token.Token;
157157
```
158158
159-
This code uses [Azure.Identity.DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) to get a useable token for SQL Database from Azure Active Directory and then adds it to the database connection. While you can customize `DefaultAzureCredential`, by default it's already very versatile. When running in App Service, it uses app's system-assigned managed identity. When running locally, it can get a token using the logged-in identity of Visual Studio, Visual Studio Code, Azure CLI, and Azure PowerShell.
159+
This code uses [Azure.Identity.DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) to get a useable token for SQL Database from Azure Active Directory and then adds it to the database connection. While you can customize `DefaultAzureCredential`, by default it's already versatile. When it runs in App Service, it uses app's system-assigned managed identity. When it runs locally, it can get a token using the logged-in identity of Visual Studio, Visual Studio Code, Azure CLI, and Azure PowerShell.
160160
161161
1. In *Web.config*, find the connection string called `MyDbConnection` and replace its `connectionString` value with `"server=tcp:<server-name>.database.windows.net;database=<db-name>;"`. Replace _\<server-name>_ and _\<db-name>_ with your server name and database name. This connection string is used by the default constructor in *Models/MyDbContext.cs*.
162162
163-
That's every thing you need to connect to SQL Database. When debugging in Visual Studio, your code uses the Azure AD user you configured in [2. Set up your dev environment](#2-set-up-your-dev-environment). You'll set up SQL Database later to allow connection from the managed identity of your App Service app.
163+
That's every thing you need to connect to SQL Database. When you debug in Visual Studio, your code uses the Azure AD user you configured in [2. Set up your dev environment](#2-set-up-your-dev-environment). You'll set up SQL Database later to allow connection from the managed identity of your App Service app.
164164
165165
1. Type `Ctrl+F5` to run the app again. The same CRUD app in your browser is now connecting to the Azure SQL Database directly, using Azure AD authentication. This setup lets you run database migrations from Visual Studio.
166166
@@ -182,7 +182,7 @@ The steps you follow for your project depends on whether you're using [Entity Fr
182182
> The [Active Directory Default](/sql/connect/ado-net/sql/azure-active-directory-authentication#using-active-directory-default-authentication) authentication type can be used both on your local machine and in Azure App Service. The driver attempts to acquire a token from Azure Active Directory using various means. If the app is deployed, it gets a token from the app's managed identity. If the app is running locally, it tries to get a token from Visual Studio, Visual Studio Code, and Azure CLI.
183183
>
184184
185-
That's everything you need to connect to SQL Database. When debugging in Visual Studio, your code uses the Azure AD user you configured in [2. Set up your dev environment](#2-set-up-your-dev-environment). You'll set up SQL Database later to allow connection from the managed identity of your App Service app. The `DefaultAzureCredential` class caches the token in memory and retrieves it from Azure AD just before expiration. You don't need any custom code to refresh the token.
185+
That's everything you need to connect to SQL Database. When you debug in Visual Studio, your code uses the Azure AD user you configured in [2. Set up your dev environment](#2-set-up-your-dev-environment). You'll set up SQL Database later to allow connection from the managed identity of your App Service app. The `DefaultAzureCredential` class caches the token in memory and retrieves it from Azure AD just before expiration. You don't need any custom code to refresh the token.
186186
187187
1. Type `Ctrl+F5` to run the app again. The same CRUD app in your browser is now connecting to the Azure SQL Database directly, using Azure AD authentication. This setup lets you run database migrations from Visual Studio.
188188

0 commit comments

Comments
 (0)