Skip to content

Commit 56ce043

Browse files
committed
edits
1 parent 95c6fa4 commit 56ce043

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

articles/app-service/tutorial-auth-aad.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ zone_pivot_groups: app-service-platform-windows-linux
1414

1515
::: zone pivot="platform-windows"
1616

17-
[Azure App Service](overview.md) provides a highly scalable, self-patching web hosting service. In addition, App Service has built-in support for [user authentication and authorization](overview-authentication-authorization.md). This tutorial shows how to secure your apps with App Service authentication and authorization. It uses an Express.js with views front end as an example. App Service authentication and authorization support all language runtimes, and you can learn how to apply it to your preferred language by following the tutorial.
17+
[Azure App Service](overview.md) provides a highly scalable, self-patching web hosting service. In addition, App Service has built-in support for [user authentication and authorization](overview-authentication-authorization.md). This tutorial shows how to secure your apps with App Service authentication and authorization. It uses an Express.js with views frontend as an example. App Service authentication and authorization support all language runtimes, and you can learn how to apply it to your preferred language by following the tutorial.
1818

1919
::: zone-end
2020

@@ -40,7 +40,7 @@ In the tutorial, you learn:
4040
4141
The authentication in this procedure is provided at the hosting platform layer by Azure App Service. You must deploy the frontend and backend app and configure authentication for this web app to be used successfully.
4242

43-
:::image type="content" source="./media/tutorial-auth-aad/front-end-app-service-to-back-end-app-service-authentication.png" alt-text="Conceptual diagram show the authentication flow from the web user to the front-end app to the back-end app.":::
43+
:::image type="content" source="./media/tutorial-auth-aad/front-end-app-service-to-back-end-app-service-authentication.png" alt-text="Conceptual diagram show the authentication flow from the web user to the frontend app to the backend app.":::
4444

4545
## Get the user profile
4646

@@ -152,79 +152,79 @@ Browse to the frontend app and return the _fake_ profile from the backend. This
152152

153153
In this step, you enable authentication and authorization for the two web apps. This tutorial uses Azure Active Directory as the identity provider.
154154

155-
You also configure the front-end app to:
155+
You also configure the frontend app to:
156156

157-
- Grant the front-end app access to the back-end app
157+
- Grant the frontend app access to the backend app
158158
- Configure App Service to return a usable token
159159
- Use the token in your code.
160160

161161
For more information, see [Configure Azure Active Directory authentication for your App Services application](configure-authentication-provider-aad.md).
162162

163-
### Enable authentication and authorization for back-end app
163+
### Enable authentication and authorization for backend app
164164

165165
1. In the [Azure portal](https://portal.azure.com) menu, select **Resource groups** or search for and select *Resource groups* from any page.
166166

167-
1. In **Resource groups**, find and select your resource group. In **Overview**, select your back-end app.
167+
1. In **Resource groups**, find and select your resource group. In **Overview**, select your backend app.
168168

169-
1. In your back-end app's left menu, select **Authentication**, and then select **Add identity provider**.
169+
1. In your backend app's left menu, select **Authentication**, and then select **Add identity provider**.
170170

171171
1. In the **Add an identity provider** page, select **Microsoft** as the **Identity provider** to sign in Microsoft and Azure AD identities.
172172

173173
1. Accept the default settings and select **Add**.
174174

175-
:::image type="content" source="./media/tutorial-auth-aad/configure-auth-back-end.png" alt-text="Screenshot of the back-end app's left menu showing Authentication/Authorization selected and settings selected in the right menu.":::
175+
:::image type="content" source="./media/tutorial-auth-aad/configure-auth-back-end.png" alt-text="Screenshot of the backend app's left menu showing Authentication/Authorization selected and settings selected in the right menu.":::
176176

177177
1. The **Authentication** page opens. Copy the **Client ID** of the Azure AD application to a notepad. You need this value later.
178178

179179
:::image type="content" source="./media/tutorial-auth-aad/get-application-id-back-end.png" alt-text="Screenshot of the Azure Active Directory Settings window showing the Azure AD App, and the Azure AD Applications window showing the Client ID to copy.":::
180180

181-
If you stop here, you have a self-contained app that's already secured by the App Service authentication and authorization. The remaining sections show you how to secure a multi-app solution by "flowing" the authenticated user from the front end to the back end.
181+
If you stop here, you have a self-contained app that's already secured by the App Service authentication and authorization. The remaining sections show you how to secure a multi-app solution by "flowing" the authenticated user from the frontend to the backend.
182182

183-
### Enable authentication and authorization for front-end app
183+
### Enable authentication and authorization for frontend app
184184

185185
1. In the [Azure portal](https://portal.azure.com) menu, select **Resource groups** or search for and select *Resource groups* from any page.
186186

187-
1. In **Resource groups**, find and select your resource group. In **Overview**, select your back-end app's management page.
187+
1. In **Resource groups**, find and select your resource group. In **Overview**, select your backend app's management page.
188188

189-
:::image type="content" source="./media/tutorial-auth-aad/portal-navigate-back-end.png" alt-text="Screenshot of the Resource groups window, showing the Overview for an example resource group and a back-end app's management page selected.":::
189+
:::image type="content" source="./media/tutorial-auth-aad/portal-navigate-back-end.png" alt-text="Screenshot of the Resource groups window, showing the Overview for an example resource group and a backend app's management page selected.":::
190190

191-
1. In your back-end app's left menu, select **Authentication**, and then select **Add identity provider**.
191+
1. In your backend app's left menu, select **Authentication**, and then select **Add identity provider**.
192192

193193
1. In the **Add an identity provider** page, select **Microsoft** as the **Identity provider** to sign in Microsoft and Azure AD identities.
194194

195195
1. Accept the default settings and select **Add**.
196196

197-
:::image type="content" source="./media/tutorial-auth-aad/configure-auth-back-end.png" alt-text="Screenshot of the back-end app's left menu showing Authentication/Authorization selected and settings selected in the right menu.":::
197+
:::image type="content" source="./media/tutorial-auth-aad/configure-auth-back-end.png" alt-text="Screenshot of the backend app's left menu showing Authentication/Authorization selected and settings selected in the right menu.":::
198198

199199
1. The **Authentication** page opens. Copy the **Client ID** of the Azure AD application to a notepad. You need this value later.
200200

201201
:::image type="content" source="./media/tutorial-auth-aad/get-application-id-back-end.png" alt-text="Screenshot of the Azure Active Directory Settings window showing the Azure AD App, and the Azure AD Applications window showing the Client ID to copy.":::
202202

203203

204-
### Grant front-end app access to back end
204+
### Grant frontend app access to backend
205205

206206
Now that you've enabled authentication and authorization to both of your apps, each of them is backed by an AD application. To complete the authentication, you need to do three things:
207207

208-
- Grant the frontend app access to the back-end app
208+
- Grant the frontend app access to the backend app
209209
- Configure App Service to return a usable token
210210
- Use the token in your code.
211211

212212
> [!TIP]
213213
> If you run into errors and reconfigure your app's authentication/authorization settings, the tokens in the token store may not be regenerated from the new settings. To make sure your tokens are regenerated, you need to sign out and sign back in to your app. An easy way to do it is to use your browser in private mode, and close and reopen the browser in private mode after changing the settings in your apps.
214214
215-
In this step, you **grant the frontend app access to the backend app** on the user's behalf. (Technically, you give the front end's _AD application_ the permissions to access the back end's _AD application_ on the user's behalf.)
215+
In this step, you **grant the frontend app access to the backend app** on the user's behalf. (Technically, you give the frontend's _AD application_ the permissions to access the backend's _AD application_ on the user's behalf.)
216216

217217
1. In the **Authentication** page for the frontend app, select your frontend app name under **Identity provider**. This app registration was automatically generated for you. Select **API permissions** in the left menu.
218218

219-
1. Select **Add a permission**, then select **My APIs** > **front-end-app-name**.
219+
1. Select **Add a permission**, then select **My APIs** > **\<front-end-app-name>**.
220220

221-
1. In the **Request API permissions** page for the back-end app, select **Delegated permissions** and **user_impersonation**, then select **Add permissions**.
221+
1. In the **Request API permissions** page for the backend app, select **Delegated permissions** and **user_impersonation**, then select **Add permissions**.
222222

223223
:::image type="content" source="./media/tutorial-auth-aad/select-permission-front-end.png" alt-text="Screenshot of the Request API permissions page showing Delegated permissions, user_impersonation, and the Add permission button selected.":::
224224

225225
### Configure App Service to return a usable access token
226226

227-
The frontend app now has the required permissions to access the back-end app as the signed-in user. In this step, you configure App Service authentication and authorization to give you a usable access token for accessing the back end. For this step, you need the back end's client ID, which you copied from [Enable authentication and authorization for back-end app](#enable-authentication-and-authorization-for-back-end-app).
227+
The frontend app now has the required permissions to access the backend app as the signed-in user. In this step, you configure App Service authentication and authorization to give you a usable access token for accessing the backend. For this step, you need the backend's client ID, which you copied from [Enable authentication and authorization for backend app](#enable-authentication-and-authorization-for-back-end-app).
228228

229229
In the Cloud Shell, run the following commands on the frontend app to add the `scope` parameter to the authentication setting `identityProviders.azureActiveDirectory.login.loginParameters`. Replace *\<front-end-app-name>* and *\<back-end-client-id>*.
230230

@@ -237,26 +237,28 @@ az webapp auth set --resource-group myAuthResourceGroup --name <front-end-app-na
237237
The commands effectively add a `loginParameters` property with additional custom scopes. Here's an explanation of the requested scopes:
238238

239239
- `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).
240-
- `api://<back-end-client-id>/user_impersonation` is an exposed API in your back-end app registration. It's the scope that gives you a JWT token that includes the back end app as a [token audience](https://wikipedia.org/wiki/JSON_Web_Token).
240+
- `api://<back-end-client-id>/user_impersonation` is an exposed API in your backend app registration. It's the scope that gives you a JWT token that includes the backend app as a [token audience](https://wikipedia.org/wiki/JSON_Web_Token).
241241
- [offline_access](../active-directory/develop/v2-permissions-and-consent.md#offline_access) is included here for convenience (in case you want to [refresh tokens](#what-happens-when-the-front-end-token-expires)).
242242

243243
> [!TIP]
244-
> - To view the `api://<back-end-client-id>/user_impersonation` scope in the Azure portal, go to the **Authentication** page for the back-end app, click the link under **Identity provider**, then click **Expose an API** in the left menu.
244+
> - To view the `api://<back-end-client-id>/user_impersonation` scope in the Azure portal, go to the **Authentication** page for the backend app, click the link under **Identity provider**, then click **Expose an API** in the left menu.
245245
> - To configure the required scopes using a web interface instead, see the Microsoft steps at [Refresh auth tokens](configure-authentication-oauth-tokens.md#refresh-auth-tokens).
246-
> - Some scopes require admin or user consent. This requirement causes the consent request page to be displayed when a user signs into the frontend app in the browser. To avoid this consent page, add the front end's app registration as an authorized client application in the **Expose an API** page by clicking **Add a client application** and supplying the client ID of the front end's app registration.
246+
> - Some scopes require admin or user consent. This requirement causes the consent request page to be displayed when a user signs into the frontend app in the browser. To avoid this consent page, add the frontend's app registration as an authorized client application in the **Expose an API** page by clicking **Add a client application** and supplying the client ID of the frontend's app registration.
247247
248248
::: zone pivot="platform-linux"
249249

250250
::: zone-end
251251

252-
Your apps are now configured. The front end is now ready to access the back end with a proper access token.
252+
Your apps are now configured. The frontend is now ready to access the backend with a proper access token.
253253

254254
For information on how to configure the access token for other providers, see [Refresh identity provider tokens](configure-authentication-oauth-tokens.md#refresh-auth-tokens).
255255

256256
## 6. Frontend calls the authenticated backend
257257

258258
The frontend app needs to pass the user's authentication with the correct `user_impersonation` scope to the backend. The following steps review the code provided in the sample for this functionality.
259259

260+
View the frontend app's source code:
261+
260262
1. Use the frontend App Service injected `x-ms-token-aad-access-token` header to programmatically get the user's accessToken.
261263

262264
```javascript
@@ -290,7 +292,7 @@ The frontend app needs to pass the user's authentication with the correct `user_
290292

291293
The App service rejects the request with a 401 HTTP error code before the request reaches your application code. When your application code is reached, extract the bearerToken to get the accessToken.
292294

293-
The local backend app in Visual Studio Code.
295+
View the backend app's source code:
294296
295297
```javascript
296298
// ./src/server.js
@@ -339,20 +341,17 @@ In the preceding steps, you created Azure resources in a resource group.
339341
```
340342

341343

342-
1. Delete app registrations for both frontend and backend apps
344+
1. Use the authentication apps' **Client ID**, you previously found and made note of in the `Enable authentication and authorization` sections for the backend and frontend apps.
345+
1. Delete app registrations for both frontend and backend apps.
343346
344347
```azurecli-interactive
345-
# list all authentication apps
346-
az ad app list --query [].[displayName,id] --output table
347-
348348
# delete app - do this for both frontend and backend app
349-
# use ID in table from previous command
350-
az ad app delete id
349+
az ad app delete <client-id>
351350
```
352351
353352
## Frequently asked questions
354353
355-
### How do I test this authentication on my local development machine?**
354+
### How do I test this authentication on my local development machine?
356355
357356
The authentication in this procedure is provided at the hosting platform layer by Azure App Service. There's no equivalent emulator. You must deploy the frontend and backend app and configuration authentication for each in order to use the authentication.
358357

@@ -397,7 +396,7 @@ Because the frontend app calls the backend app from server source code, this isn
397396
* 404: The URL to the server doesn't match a route the server has
398397
* Use the backend app's streaming logs to watch as you make the frontend request for the user's profile. There's debug information in the source code with `console.log` which helps determine where the failure happened.
399398
400-
### What happens when the front-end token expires?
399+
### What happens when the frontend token expires?
401400
402401
Your access token expires after some time. For information on how to refresh your access tokens without requiring users to reauthenticate with your app, see [Refresh identity provider tokens](configure-authentication-oauth-tokens.md#refresh-auth-tokens).
403402

0 commit comments

Comments
 (0)