[AZURE.INCLUDE app-service-mobile-selector-authentication]
This topic shows you how to configure Azure App Services to use Azure Active Directory as an authentication provider.
[AZURE.NOTE] This topic demonstrates use of the App Service Authentication / Authorization feature. This replaces the App Service gateway for most applications. If using the gateway, please see the alternative method. Differences that apply to using the gateway are called out in notes throughout that section.
-
In the Azure portal, navigate to your application. Click Settings, and then Authentication/Authorization.
-
If the Authentication / Authorization feature is not enabled, turn the switch to On.
-
Click Azure Active Directory, and then click Express under Management Mode.
-
Click OK to register the application in Azure Active Directory. This will create a new registration. If you wish to choose an existing registration instead, click Select an existing app and then search for the name of a previously created registration within your tenant. Click the registration to select it and click OK. Then click OK on the Azure Active Directory settings blade.
By default, App Service provides authentication but does not restrict authorized access to your site content and APIs. You must authorize users in your app code.
-
(Optional) To restrict access to your site to only users authenticated by Azure Active Directory, set Action to take when request is not authenticated to Log in with Azure Active Directory. This requires that all requests be authenticated, and all unauthenticated requests are redirected to Azure Active Directory for authentication.
-
Click Save.
You are now ready to use Azure Active Directory for authentication in your app.
You can also choose to provide configuration settings manually. This is the preferred solution if the AAD tenant you wish to use is different from the tenant with which you sign into Azure. To complete the configuration, you must first create a registration in Azure Active Directory, and then you must provide some of the registration details to App Service.
-
Log on to the Azure portal, and navigate to your application. Copy your URL. You will use this to configure your Azure Active Directory app.
-
Sign in to the Azure classic portal and navigate to Active Directory.
-
Select your directory, and then select the Applications tab at the top. Click ADD at the bottom to create a new app registration.
-
Click Add an application my organization is developing.
-
In the Add Application Wizard, enter a Name for your application and click the Web Application And/Or Web API type. Then click to continue.
-
In the SIGN-ON URL box, paste the application URL you copied earlier. Enter that same URL in the App ID URI box. Then click to continue.
-
Once the application has been added, click the Configure tab. Edit the Reply URL under Single Sign-on to be the the URL of your application appended with the path, /.auth/login/aad/callback. For example,
https://contoso.azurewebsites.net/.auth/login/aad/callback
. Make sure that you are using the HTTPS scheme.[AZURE.NOTE] If you are using the App Service Gateway instead of the App Service Authentication / Authorization feature, your Reply URL instead uses the gateway URL with the /signin-aad path.
-
Click Save. Then copy the Client ID for the app. You will configure your application to use this later.
-
In the bottom command bar, click View Endpoints, and then copy the Federation Metadata Document URL and download that document or navigate to it in a browser.
-
Within the root EntityDescriptor element, there should be an entityID attribute of the form
https://sts.windows.net/
followed by a GUID specific to your tenant (called a "tenant ID"). Copy this value - it will serve as your Issuer URL. You will configure your application to use this later.
[AZURE.NOTE] If using the App Service Gateway, ignore this section and instead navigate to your gateway in the portal. Select Settings, Identity, and then Azure Active Directory. Paste in the ClientID and add the tenant ID to the Allowed Tenants list. Click Save.
-
Back in the Azure portal, navigate to your application. Click Settings, and then Authentication/Authorization.
-
If the Authentication/Authorization feature is not enabled, turn the switch to On.
-
Click Azure Active Directory, and then click Advanced under Management Mode. Paste in the Client ID and Issuer URL value which you obtained previously. Then click OK.
By default, App Service provides authentication but does not restrict authorized access to your site content and APIs. You must authorize users in your app code.
-
(Optional) To restrict access to your site to only users authenticated by Azure Active Directory, set Action to take when request is not authenticated to Log in with Azure Active Directory. This requires that all requests be authenticated, and all unauthenticated requests are redirected to Azure Active Directory for authentication.
-
Click Save.
You are now ready to use Azure Active Directory for authentication in your app.
Azure Active Directory also allows you to register native clients, which provides greater control over permissions mapping. You need this if you wish to perform logins using a library such as the Active Directory Authentication Library.
-
Navigate to Active Directory in the Azure classic portal.
-
Select your directory, and then select the Applications tab at the top. Click ADD at the bottom to create a new app registration.
-
Click Add an application my organization is developing.
-
In the Add Application Wizard, enter a Name for your application and click the Native Client Application type. Then click to continue.
-
In the Redirect URI box, enter your site's /.auth/login/done endpoint, using the HTTPS scheme. This value should be similar to https://contoso.azurewebsites.net/.auth/login/done.
-
Once the native application has been added, click the Configure tab. Find the Client ID and make a note of this value.
-
Scroll the page down to the Permissions to other applications section and click Add application.
-
Search for the web application that you registered earlier and click the plus icon. Then click the check to close the dialog. If the web application cannot be found, navigate to its registration and add a new reply URL (e.g., the HTTP version of your current URL), click save, and then repeat these steps - the application should show up in the list.
-
On the new entry you just added, open the Delegated Permissions dropdown and select Access (appName). Then click Save.
You have now configured a native client application which can access your App Service application.
[AZURE.INCLUDE app-service-mobile-related-content-get-started-users]