| title | Tutorial - Add authentication to a web app on Azure App Service | Azure | ||
|---|---|---|---|
| description | In this tutorial, you learn how to enable authentication and authorization for a web app running on Azure App Service. Limit access to the web app to users in your organization. | ||
| author | cephalin | ||
| ms.author | cephalin | ||
| ms.service | azure-app-service | ||
| ms.topic | include | ||
| ms.date | 11/29/2024 | ||
| ms.custom |
|
[!INCLUDE quickstarts-free-trial-note]
For this tutorial, you need a web app deployed to App Service. You can use an existing web app, or you can follow one of the quickstarts to create and publish a new web app to App Service:
Whether you use an existing web app or create a new one, take note of the following:
- Web app name.
- Resource group that the web app is deployed to.
You need these names throughout this tutorial.
Now that you have a web app running on App Service, enable authentication and authorization. You use Microsoft Entra as the identity provider. For more information, see Configure Microsoft Entra authentication for your App Service application.
-
In the Azure portal menu, select Resource groups, or search for and select Resource groups from any page.
-
In Resource groups, find and select your resource group. In Overview, select your app's management page.
:::image type="content" alt-text="Screenshot that shows selecting your app's management page." source="../../media/scenario-secure-app-authentication-app-service/select-app-service.png":::
-
On your app's left menu, select Authentication, and then select Add identity provider.
-
In the Add an identity provider page, select Microsoft as the Identity provider to sign in Microsoft and Microsoft Entra identities.
-
For Tenant type, select Workforce configuration (current tenant) for employees and business guests.
-
For App registration > App registration type, select Create new app registration to create a new app registration in Microsoft Entra.
-
Enter a display Name for your application. Users of your application might see the display name when they use the app, for example during sign-in.
-
For Client secret expiration, select Recommended: 180 days.
-
For App registration > Supported account types, select Current tenant-single tenant so only users in your organization can sign in to the web app.
-
In the Additional checks section, select:
- Allow requests only from this application itself for Client application requirement
- Allow requests from any identity for Identity requirement
- Allow requests only from the issuer tenant for Tenant requirement
-
In the App Service authentication settings section, set:
- Require authentication for Authentication
- HTTP 302 Found redirect: recommended for websites for Unauthenticated requests
- Token store box
-
At the bottom of the Add an identity provider page, select Add to enable authentication for your web app.
:::image type="content" alt-text="Screenshot that shows configuring authentication." source="../../media/scenario-secure-app-authentication-app-service/configure-authentication.png":::
You now have an app that's secured by the App Service authentication and authorization.
[!NOTE] To allow accounts from other tenants, change the 'Issuer URL' to 'https://login.microsoftonline.com/common/v2.0' by editing your 'Identity Provider' from the 'Authentication' blade.
-
In the Azure portal menu, select Resource groups, or search for and select Resource groups from any page.
-
In Resource groups, find and select your resource group. In Overview, select your app's management page.
:::image type="content" alt-text="Screenshot that shows selecting your app's management page." source="../../media/scenario-secure-app-authentication-app-service/select-app-service.png":::
-
On your app's left menu, select Authentication, and then select Add identity provider.
-
In the Add an identity provider page, select Microsoft as the Identity provider to sign in Microsoft and Microsoft Entra identities.
-
For Tenant type, select External configuration for external users.
-
Select Create new app registration to create a new app registration.
-
Select an existing tenant to use from the drop-down, or select Create new to create a new external tenant.
:::image type="content" alt-text="Screenshot that shows the Select a tenant dropdown." source="../../media/scenario-secure-app-authentication-app-service/configure-authentication-external-select.png":::
-
(Optional) In the Create a tenant page, add the Tenant Name* and Domain Name. Select a Location and select Review and create and then Create.
:::image type="content" alt-text="Screenshot the Create a tenant page." source="../../media/scenario-secure-app-authentication-app-service/configure-authentication-external-create-tenant.png":::
-
Select Configure to configure external authentication.
-
The browser opens Configure customer authentication. In Setup sign-in, select Create new to create a sign-in experience for your external users.
-
Enter a Name for the user flow.
-
For this quickstart, select Email and password which allows new users to sign up and sign in using an email address as the sign-in name and a password as their first factor credential.
-
Select Create to create the user flow.
:::image type="content" alt-text="Screenshot that shows creating a user flow." source="../../media/scenario-secure-app-authentication-app-service/configure-authentication-external-user-flow.png":::
-
Select Next to customize branding.
-
Add your company logo, select a background color, and select a sign-in layout.
:::image type="content" alt-text="Screenshot that shows the customized branding tab." source="../../media/scenario-secure-app-authentication-app-service/configure-authentication-branding.png":::
-
Select Next. If the tenant you selected already has a branding configuration you will need to confirm that you want to override it.
-
Select Configure in the Review tab to confirm external tenant update.
-
The browser returns to the Add an identity provider page.
-
In the Additional checks section, select:
- Allow requests only from this application itself for Client application requirement
- Allow requests from any identity for Identity requirement
- Allow requests only from the issuer tenant for Tenant requirement
-
In the App Service authentication settings section, set:
- Require authentication for Authentication
- HTTP 302 Found redirect: recommended for websites for Unauthenticated requests
- Token store box
-
At the bottom of the Add an identity provider page, select Add to enable authentication for your web app.
:::image type="content" alt-text="Screenshot that shows the Additional checks and authentication settings sections." source="../../media/scenario-secure-app-authentication-app-service/configure-authentication-external-enable.png":::
When you enabled the App Service authentication/authorization module in the previous section, an app registration was created in your workforce or external tenant. The app registration has the display name you created in a previous step.
-
To check the settings, sign in to the Microsoft Entra admin center as at least an Application Developer.
-
If you chose external configuration, use the Settings icon in the top menu to switch to the external tenant with your web app from the Directories + subscriptions menu.
-
Browse to Identity > Applications > App registrations and select Applications > App registrations from the menu.
-
Select the app registration that was created.
-
In the overview, verify that Supported account types is set to My organization only.
-
To verify that access to your app is limited to users in your organization, go to your web app Overview and select the Default domain link.
:::image type="content" alt-text="Screenshot that shows verifying access." source="../../media/scenario-secure-app-authentication-app-service/verify-access.png":::
-
You should be directed to a secured sign-in page, verifying that unauthenticated users aren't allowed access to the site.
-
Sign in as a user in your organization to gain access to the site.
-
To verify that users outside the organization don't have access, open another incognito or private browser window and try to sign in by using a personal Microsoft account. The sign-in should fail or be denied.
[!INCLUDE clean up resources]
In this tutorial, you learned how to:
[!div class="checklist"]
- Configure authentication for the web app.
- Limit access to the web app to users in your organization.