|
1 | | -# Azure App Registrations Setup |
| 1 | +# Set up Authentication in Azure Container App |
2 | 2 |
|
3 | 3 | This document provides step-by-step instructions to configure Azure App Registrations for a front-end and back-end application. |
4 | 4 |
|
5 | 5 | ## Prerequisites |
| 6 | + |
6 | 7 | - Access to **Azure Active Directory (Azure AD)** |
7 | 8 | - Necessary permissions to create and manage **App Registrations** |
8 | 9 |
|
9 | | -## Step 1: Create Back-End App Registration |
10 | | -1. Go to the [Azure Portal](https://portal.azure.com/). |
11 | | -1. Navigate to **App registrations**. |
12 | | -1. Click **New registration**. |
13 | | -1. Provide a **Name** for the back-end app (e.g., `cps-backend-<env_name>-app`). |
14 | | -1. Choose **Supported account types**. |
15 | | -1. Click **Register**. |
16 | | - |
17 | | -### Step 1.1: Expose an API for the Back-End App |
18 | | -1. In the back-end app registration, go to **Expose an API**. |
19 | | -1. Click **Add a scope**. |
20 | | -1. Click **Save and Continue**. |
21 | | -1. Set the **Scope name** to `user_impersonation`. |
22 | | -1. Set the **Admin consent display name** to `user_impersonation`. |
23 | | -1. Provide a description and enable **Admin consent**. |
24 | | -1. Click **Add Scope**. |
25 | | -1. Copy the **Scope value**. |
26 | | -1. Go to the **Overview** section and copy the **Client ID** of the back-end app. |
27 | | - |
28 | | -### Step 1.2: Generate Client Secret |
29 | | -1. In the back-end app registration, go to **Certificates & secrets**. |
30 | | -1. Click **New Client Secret**. |
31 | | -1. Enter a **Description**. |
32 | | -1. Select the **Expiration time** for the secret. |
33 | | -1. Click **Add**. |
34 | | -1. Copy the **Secret value**. |
35 | | - |
36 | | -## Step 2: Copy Front-End App URL from Azure Container Apps |
37 | | -1. Navigate to the **Resource Group** where your Azure resources are deployed. |
38 | | -1. Select the deployed front-end application named **ca-cps-<env_name>-web**. |
39 | | -1. Copy the **Front-End Application URL** displayed under the **Overview** section. |
40 | | - |
41 | | -## Step 3: Create Front-End App Registration |
42 | | -1. Navigate to **App registrations**. |
43 | | -1. Click **New registration**. |
44 | | -1. Provide a **Name** for the front-end app (e.g., `cps-frontend-<env_name>-app`). |
45 | | -1. Choose **Supported account types** as per your requirement. |
46 | | -1. In the **Redirect URI** section, select **Single-page application** and paste the copied **Front-End Application URL** from Step 2 in the textbox next to it. |
47 | | -1. Click **Register**. |
48 | | - |
49 | | -### Step 3.1: Expose an API for the Front-End App |
50 | | -1. In the front-end app registration, go to **Expose an API**. |
51 | | -1. Click **Add a scope**. |
52 | | -1. Click **Save and Continue**. |
53 | | -1. Set the **Scope name** to `user_impersonation`. |
54 | | -1. Set the **Admin consent display name** to `user_impersonation`. |
55 | | -1. Provide a description and enable **Admin consent**. |
56 | | -1. Click **Add Scope**. |
57 | | -1. Copy the **Scope value**. |
58 | | -1. Go to the **Overview** section and copy the **Client ID** of the app. |
59 | | - |
60 | | -### Step 3.2: Configure API Permissions in the Front-End App |
61 | | -1. In the front-end app registration, go to **API permissions**. |
62 | | -1. Click **Add a permission**. |
63 | | -1. Select **My APIs**. |
64 | | -1. Select the back-end app registration created in Step 1. |
65 | | -1. If you don’t find it under **My APIs**, search under **APIs My organization uses**. |
66 | | -1. Choose the `user_impersonation` permission. |
67 | | -1. Click **Add permissions**. |
68 | | -1. Click **Grant admin consent**. |
69 | | - |
70 | | -## Step 4: Configure Authentication Settings in the Front-End Container App (Web) |
71 | | -1. Navigate to the **Resource Group** where your Azure resources are deployed. |
72 | | -1. Select the deployed front-end application named **ca-cps-<env_name>-web**. |
73 | | -1. Click **Containers** under **Application** from the left-side menu. |
74 | | -1. Click **Environment variables**. |
75 | | -1. For the key **APP_MSAL_AUTH_CLIENT_ID**, add the front-end app **Client ID** copied from Step 3.1. |
76 | | -1. For the key **APP_MSAL_AUTH_SCOPE**, add the scope copied from Step 3.1. |
77 | | -1. For the key **APP_MSAL_TOKEN_SCOPE**, add the scope copied from Step 1.1. |
78 | | -1. Click **Save as a new revision**. |
79 | | - |
80 | | -## Step 5: Configure Identity Provider in the Back-End Container App (API) |
81 | | -1. Navigate to the **Resource Group** where your Azure resources are deployed. |
82 | | -1. Select the deployed back-end application named **ca-cps-<env_name>-api**. |
83 | | -1. Under **Settings**, go to **Authentication**. |
84 | | -1. Click **Add Identity Provider**. |
85 | | -1. Select the **Identity Provider** as **Microsoft**. |
86 | | -1. Select **Provide the details of an existing app registration**. |
87 | | -1. Enter the **Back-End API App Client ID** copied from Step 1.1 into the **Application (client) ID** field. |
88 | | -1. Enter the **Client Secret** generated in Step 1.2 into the **Client secret (recommended)** field. |
89 | | -1. Under **Allowed token audiences**, add the value **api://<Back-End App Client ID>**. |
90 | | -1. Under **Client application requirement**, select **Allow requests from specific client applications**. |
91 | | -1. Click the **Edit** icon under the **Allowed client applications** section. |
92 | | -1. Add the **Client ID of the Back-End App** copied from Step 1.1. |
93 | | -1. Add the **Client ID of the Front-End App** copied from Step 3.1. |
94 | | -1. Click **OK**. |
95 | | -1. Under the **Unauthenticated requests** section, select **HTTP 401 Unauthorized: recommended for APIs**. |
96 | | -1. Click **Add**. |
| 10 | +## Step 1: Add Authentication Provider |
| 11 | + |
| 12 | +We will add Microsoft Entra ID as an authentication provider to API and Web Application. |
| 13 | + |
| 14 | +1. Add Authentication Provider in Web Application |
| 15 | + |
| 16 | + - Go to deployed Container App and select `ca-<your environment>-<randomname>-web` and click **Add Identity Provider** button in Authentication. |
| 17 | +  |
| 18 | + |
| 19 | + - Select **Microsoft** and set **Client secret expiration**, then click **Add** button. |
| 20 | +  |
| 21 | + |
| 22 | +2. Add Authentication Provider in API Service |
| 23 | + |
| 24 | + - Go to deployed Container App and select `ca-<your environment>-<randomname>-api` and click **Add Identity Provider** button in Authentication. |
| 25 | +  |
| 26 | + |
| 27 | + - Select **Microsoft** and set **Client secret expiration**. |
| 28 | +  |
| 29 | + |
| 30 | + - Set **Unauthenticated requests**, then click **Add** button. |
| 31 | +  |
| 32 | + |
| 33 | +## Step 2: Configure Application Registration - Web Application |
| 34 | + |
| 35 | +1. Set Redirect URI in Single Page Application Platform |
| 36 | + |
| 37 | + - Go to deployed Container App `ca-<your environment>-<randomname>-web` and select **Authentication** menu, then select created Application Registration. |
| 38 | +  |
| 39 | + |
| 40 | + - Select **Authentication**, then select **+ Add a platform** menu. |
| 41 | +  |
| 42 | + |
| 43 | + - Select **Single-page application**. |
| 44 | +  |
| 45 | + |
| 46 | + - Add Container App `ca-<your environment>-<randomname>-web`'s URL. |
| 47 | +  |
| 48 | + |
| 49 | + - You may get this URL from here in your Container App. |
| 50 | +  |
| 51 | + |
| 52 | +2. Add Permission and Grant Permission |
| 53 | + |
| 54 | + - Add Permission for API application. Select **+ Add a permission** button, then search API application with name `ca-<your environment name>-<unique string>-api`. |
| 55 | +  |
| 56 | +  |
| 57 | + |
| 58 | + - Grant admin consent to permissions. |
| 59 | +  |
| 60 | + |
| 61 | +3. Grab Scope Name for Impersonation |
| 62 | + |
| 63 | + - Select **Expose an API** in the left menu. Copy the Scope name, then paste it in some temporary place. |
| 64 | + The copied text will be used for Web Application Environment variable - **APP_MSAL_AUTH_SCOPE**. |
| 65 | +  |
| 66 | + |
| 67 | +4. Grab Client Id for Web App |
| 68 | + |
| 69 | + - Select **Overview** in the left menu. Copy the Client Id, then paste it in some temporary place. |
| 70 | + The copied text will be used for Web Application Environment variable - **APP_MSAL_AUTH_CLIENT_ID**. |
| 71 | +  |
| 72 | + |
| 73 | +## Step 3: Configure Application Registration - API Application |
| 74 | + |
| 75 | +1. Grab Scope Name for Impersonation |
| 76 | + |
| 77 | + - Go to deployed Container App `ca-<your environment>-<randomname>-api` and select **Authentication** menu, then select created Application Registration. |
| 78 | +  |
| 79 | + |
| 80 | + - Select **Expose an API** in the left menu. Copy the Scope name, then paste it in some temporary place. |
| 81 | + The copied text will be used for Web Application Environment variable - **APP_MSAL_TOKEN_SCOPE**. |
| 82 | +  |
| 83 | + |
| 84 | +## Step 4: Add Web Application's Client Id to Allowed Client Applications List in API Application Registration |
| 85 | + |
| 86 | +1. Go to the deployed Container App `ca-<your environment>-<randomname>-api`, select **Authentication**, and then click **Edit**. |
| 87 | +  |
| 88 | + |
| 89 | +2. Select **Allow requests from specific client applications**, then click the **pencil** icon to add the Client Id. |
| 90 | +  |
| 91 | + |
| 92 | +3. Add the **Client Id** obtained from [Step 2: Configure Application Registration - Web Application](#step-2-configure-application-registration---web-application), then save. |
| 93 | +  |
| 94 | + |
| 95 | +## Step 5: Update Environment Variable in Container App for Web Application |
| 96 | + |
| 97 | +In previous steps for [Configure Application Registration - Web Application](#step-2-configure-application-registration---web-application) and [Configure Application Registration - API Application](#step-3-configure-application-registration---api-application), we grabbed Client Id for Web App's Application Registration and Scopes for Web and API's Application Registration. |
| 98 | + |
| 99 | +Now, we will edit and deploy the Web Application Container with updated Environment variables. |
| 100 | + |
| 101 | +1. Select **Containers** menu under **Application**, then click **Edit and Deploy** menu. |
| 102 | +  |
| 103 | + |
| 104 | +2. Select Container image and click **Edit**. Under **Environment variables** section, update 3 values which were taken in previous steps for **APP_MSAL_AUTH_CLIENT_ID**, **APP_MSAL_AUTH_SCOPE**, **APP_MSAL_TOKEN_SCOPE**. |
| 105 | + The updated revision will be activated soon. |
97 | 106 |
|
98 | 107 | ## Conclusion |
| 108 | + |
99 | 109 | You have successfully configured the front-end and back-end Azure App Registrations with proper API permissions and security settings. |
0 commit comments