Perform the following steps:
- Navigate to the Platform features section of Azure Functions.
- In the Authentication/Authorization blade, perform the following steps to enable the AD authentication:
- Click on the On button to enable the authentication.
- Choose the Login using Azure Active Directory menu option.
- Click on the Not Configured button to start configuring the options.
- The next step is to choose an existing or create a new registration for the client application that we want to provide access to. This can be done by pressing the Express button in the Management Mode field. Also, I opted to create a new one and provided AzureFunctionCookbookV2 as the name for my app registration. Click OK to save the configurations, which will take you to the following screen.
- Grab the Application ID as shown. We will be using it while testing in a few moments:
- That's it. Without writing a single line of code, we are done with configuring an Azure AD instance that sits as a security layer and allows access only to authenticated users. In other words, we have enabled OAuth for our backend function app using Azure AD. Let's quickly test it by accessing any of the HTTP triggers that you have in the function app. I have used Postman to do this. As expected, you will get an error asking you to log in.
- With the current configurations, none of the external client applications will be able to access our backend API. In order to provide access, we need to perform the following steps:
- Register all the client apps in Azure AD (for our example, we will do a registration for the Postman app).
- Grant access to the backend app.