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: articles/app-service/app-service-web-tutorial-auth-aad.md
+48-47Lines changed: 48 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,11 @@
1
1
---
2
-
title: 'Tutorial: AuthN/AuthO end-to-end'
3
-
description: Learn how to use App Service authentication and authorization to secure your App Service apps, including access to remote APIs.
2
+
title: 'Tutorial: Authenticate users E2E'
3
+
description: Learn how to use App Service authentication and authorization to secure your App Service apps end-to-end, including access to remote APIs.
4
4
keywords: app service, azure app service, authN, authZ, secure, security, multi-tiered, azure active directory, azure ad
5
5
ms.devlang: dotnet
6
6
ms.topic: tutorial
7
-
ms.date: 08/14/2019
7
+
ms.date: 04/29/2020
8
8
ms.custom: seodec18
9
-
10
9
---
11
10
12
11
# Tutorial: Authenticate and authorize users end-to-end in Azure App Service
@@ -42,8 +41,8 @@ You can follow the steps in this tutorial on macOS, Linux, Windows.
@@ -205,37 +204,37 @@ You use Azure Active Directory as the identity provider. For more information, s
205
204
206
205
### Enable authentication and authorization for back-end app
207
206
208
-
1.In the [Azure portal](https://portal.azure.com) menu, select **Resource groups** or search for and select *Resource groups* from any page.
207
+
In the [Azure portal](https://portal.azure.com) menu, select **Resource groups** or search for and select *Resource groups* from any page.
209
208
210
-
1.In **Resource groups**, find and select your resource group. In **Overview**, select your back-end app's management page.
209
+
In **Resource groups**, find and select your resource group. In **Overview**, select your back-end app's management page.
211
210
212
-

211
+

213
212
214
-
1.In your back-end app's left menu, select **Authentication / Authorization**, then enable App Service Authentication by selecting **On**.
213
+
In your back-end app's left menu, select **Authentication / Authorization**, then enable App Service Authentication by selecting **On**.
215
214
216
-
1.In **Action to take when request is not authenticated**, select **Log in with Azure Active Directory**.
215
+
In **Action to take when request is not authenticated**, select **Log in with Azure Active Directory**.
217
216
218
-
1.Under **Authentication Providers**, select **Azure Active Directory**
217
+
Under **Authentication Providers**, select **Azure Active Directory**.
219
218
220
-

219
+

221
220
222
-
1.Select **Express**, then accept the default settings to create a new AD app and select **OK**.
221
+
Select **Express**, then accept the default settings to create a new AD app and select **OK**.
223
222
224
-
1.In the **Authentication / Authorization** page, select **Save**.
223
+
In the **Authentication / Authorization** page, select **Save**.
225
224
226
-
Once you see the notification with the message `Successfully saved the Auth Settings for <back-end-app-name> App`, refresh the page.
225
+
Once you see the notification with the message `Successfully saved the Auth Settings for <back-end-app-name> App`, refresh the portal page.
227
226
228
-
1.Select **Azure Active Directory** again, and then select the **Azure AD App**.
227
+
Select **Azure Active Directory** again, and then select the **Azure AD App**.
229
228
230
-
1.Copy the **Client ID** of the Azure AD application to a notepad. You need this value later.
229
+
Copy the **Client ID** of the Azure AD application to a notepad. You need this value later.
231
230
232
-

231
+

233
232
234
233
### Enable authentication and authorization for front-end app
235
234
236
-
Follow the same steps for the back-end app, but skip the last step. You don't need the client ID for the front-end app.
235
+
Follow the same steps for the front-end app, but skip the last step. You don't need the client ID for the front-end app.
237
236
238
-
If you like, navigate to `http://<front-end-app-name>.azurewebsites.net`. It should now direct you to a secured sign-in page. After you sign in, you still can't access the data from the back-end app, because you still need to do three things:
237
+
If you like, navigate to `http://<front-end-app-name>.azurewebsites.net`. It should now direct you to a secured sign-in page. After you sign in, *you still can't access the data from the back-end app*, because the back-end app now requires Azure Active Directory sign-in from the front-end app. You need to do three things:
239
238
240
239
- Grant the front end access to the back end
241
240
- Configure App Service to return a usable token
@@ -248,27 +247,29 @@ If you like, navigate to `http://<front-end-app-name>.azurewebsites.net`. It sho
248
247
249
248
Now that you've enabled authentication and authorization to both of your apps, each of them is backed by an AD application. In this step, you give the front-end app permissions to access the back end 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.)
250
249
251
-
1.In the [Azure portal](https://portal.azure.com) menu, select **Azure Active Directory** or search for and select *Azure Active Directory* from any page.
250
+
In the [Azure portal](https://portal.azure.com) menu, select **Azure Active Directory** or search for and select *Azure Active Directory* from any page.
252
251
253
-
1.Select **App registrations** > **Owned applications**. Select your front-end app name, then select **API permissions**.
252
+
Select **App registrations** > **Owned applications** > **View all applications in this directory**. Select your front-end app name, then select **API permissions**.
254
253
255
-

254
+

256
255
257
-
1.Select **Add a permission**, then select **My APIs** > **\<back-end-app-name>**.
256
+
Select **Add a permission**, then select **APIs my organization uses** > **\<back-end-app-name>**.
258
257
259
-
1.In the **Request API permissions** page for the back-end app, select **Delegated permissions** and **user_impersonation**, then select **Add permissions**.
258
+
In the **Request API permissions** page for the back-end app, select **Delegated permissions** and **user_impersonation**, then select **Add permissions**.
260
259
261
-

260
+

262
261
263
262
### Configure App Service to return a usable access token
264
263
265
264
The front-end 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).
266
265
267
-
Sign in to [Azure Resource Explorer](https://resources.azure.com). At the top of the page, click **Read/Write** to enable editing of your Azure resources.
266
+
In your front-end app's left menu, select **Resource explorer** under **Development Tools**, then select **Go**.
267
+
268
+
The [Azure Resource Explorer](https://resources.azure.com) is now opened with your front-end app selected in the resource tree. At the top of the page, click **Read/Write** to enable editing of your Azure resources.
268
269
269
270

270
271
271
-
In the left browser, click **subscriptions** > **_\<your-subscription>_** > **resourceGroups** > **myAuthResourceGroup** > **providers** > **Microsoft.Web** > **sites** > **_\<front-end-app-name>_** >**config** > **authsettings**.
272
+
In the left browser, drill down to**config** > **authsettings**.
272
273
273
274
In the **authsettings** view, click **Edit**. Set `additionalLoginParams` to the following JSON string, using the client ID you copied.
274
275
@@ -306,7 +307,7 @@ public override void OnActionExecuting(ActionExecutingContext context)
306
307
}
307
308
```
308
309
309
-
This code adds the standard HTTP header `Authorization: Bearer <access-token>` to all remote API calls. In the ASP.NET Core MVC request execution pipeline, `OnActionExecuting` executes just before the respective action method (such as `GetAll()`) does, so each of your outgoing API call now presents the access token.
310
+
This code adds the standard HTTP header `Authorization: Bearer <access-token>` to all remote API calls. In the ASP.NET Core MVC request execution pipeline, `OnActionExecuting` executes just before the respective action does, so each of your outgoing API call now presents the access token.
310
311
311
312
Save all your changes. In the local terminal window, deploy your changes to the front-end app with the following Git commands:
312
313
@@ -329,15 +330,15 @@ In this step, you point the front-end Angular.js app to the back-end API. This w
329
330
While the server code has access to request headers, client code can access `GET /.auth/me` to get the same access tokens (see [Retrieve tokens in app code](app-service-authentication-how-to.md#retrieve-tokens-in-app-code)).
330
331
331
332
> [!TIP]
332
-
> This section uses the standard HTTP methods to demonstrate the secure HTTP calls. However, you can use [Active Directory Authentication Library (ADAL) for JavaScript](https://github.com/AzureAD/azure-activedirectory-library-for-js) to help simplify the Angular.js application pattern.
333
+
> This section uses the standard HTTP methods to demonstrate the secure HTTP calls. However, you can use [Microsoft Authentication Library for JavaScript](https://github.com/AzureAD/microsoft-authentication-library-for-js) to help simplify the Angular.js application pattern.
333
334
>
334
335
335
336
### Configure CORS
336
337
337
-
In the Cloud Shell, enable CORS to your client's URL by using the [`az resource update`](/cli/azure/resource#az-resource-update) command. Replace the _\<back-end-app-name>_ and _\<front-end-app-name>_ placeholders.
338
+
In the Cloud Shell, enable CORS to your client's URL by using the [`az webapp cors add`](/cli/azure/webapp/cors#az-webapp-cors-add) command. Replace the _\<back-end-app-name>_ and _\<front-end-app-name>_ placeholders.
338
339
339
340
```azurecli-interactive
340
-
az resource update --name web --resource-group myAuthResourceGroup --namespace Microsoft.Web --resource-type config --parent sites/<back-end-app-name> --set properties.cors.allowedOrigins="['https://<front-end-app-name>.azurewebsites.net']" --api-version 2015-06-01
341
+
az webapp cors add --resource-group myAuthResourceGroup --name <back-end-app-name> --allowed-origins 'https://<front-end-app-name>.azurewebsites.net'
341
342
```
342
343
343
344
This step is not related to authentication and authorization. However, you need it so that your browser allows the cross-domain API calls from your Angular.js app. For more information, see [Add CORS functionality](app-service-web-tutorial-rest-api.md#add-cors-functionality).
@@ -346,7 +347,7 @@ This step is not related to authentication and authorization. However, you need
346
347
347
348
In the local repository, open _wwwroot/index.html_.
348
349
349
-
In Line 51, set the `apiEndpoint` variable to the URL of your back-end app (`https://<back-end-app-name>.azurewebsites.net`). Replace _\<back-end-app-name>_ with your app name in App Service.
350
+
In Line 51, set the `apiEndpoint` variable to the HTTPS URL of your back-end app (`https://<back-end-app-name>.azurewebsites.net`). Replace _\<back-end-app-name>_ with your app name in App Service.
350
351
351
352
In the local repository, open _wwwroot/app/scripts/todoListSvc.js_ and see that `apiEndpoint` is prepended to all the API calls. Your Angular.js app is now calling the back-end APIs.
352
353
@@ -432,7 +433,7 @@ What you learned:
432
433
> * Use access tokens from server code
433
434
> * Use access tokens from client (browser) code
434
435
435
-
Advance to the next tutorial to learn how to map a custom DNS name to your web app.
436
+
Advance to the next tutorial to learn how to map a custom DNS name to your app.
436
437
437
438
> [!div class="nextstepaction"]
438
439
> [Map an existing custom DNS name to Azure App Service](app-service-web-tutorial-custom-domain.md)
remote: App container will begin restart within 10 seconds.
117
118
To https://<app_name>.scm.azurewebsites.net/<app_name>.git
118
119
* [new branch] master -> master
119
120
</pre>
@@ -154,10 +155,10 @@ In production, your browser app would have a public URL instead of the localhost
154
155
155
156
### Enable CORS
156
157
157
-
In the Cloud Shell, enable CORS to your client's URL by using the [`az resource update`](/cli/azure/resource#az-resource-update) command. Replace the _<appname>_ placeholder.
158
+
In the Cloud Shell, enable CORS to your client's URL by using the [`az webapp cors add`](/cli/azure/webapp/cors#az-webapp-cors-add) command. Replace the _<app-name>_ placeholder.
158
159
159
160
```azurecli-interactive
160
-
az resource update --name web --resource-group myResourceGroup --namespace Microsoft.Web --resource-type config --parent sites/<app_name> --set properties.cors.allowedOrigins="['http://localhost:5000']" --api-version 2015-06-01
161
+
az webapp cors add --resource-group myResourceGroup --name <app-name> --allowed-origins 'http://localhost:5000'
161
162
```
162
163
163
164
You can set more than one client URL in `properties.cors.allowedOrigins` (`"['URL1','URL2',...]"`). You can also enable all client URLs with `"['*']"`.
0 commit comments