|
| 1 | +--- |
| 2 | +title: Tutorial - Customize the user interface of your applications in Azure Active Directory B2C | Microsoft Docs |
| 3 | +description: Learn how to customize the user interface of your applications in Azure Active Directory B2C using the Azure portal. |
| 4 | +services: B2C |
| 5 | +author: davidmu1 |
| 6 | +manager: mtillman |
| 7 | + |
| 8 | +ms.service: active-directory |
| 9 | +ms.workload: identity |
| 10 | +ms.topic: conceptual |
| 11 | +ms.date: 10/30/2018 |
| 12 | +ms.author: davidmu |
| 13 | +ms.component: B2C |
| 14 | +--- |
| 15 | + |
| 16 | +# Tutorial: Customize the user interface of your applications in Azure Active Directory B2C |
| 17 | + |
| 18 | +For more common user experiences, such as sign-up, sign-in, and profile editing, you can use [built-in policies](active-directory-b2c-reference-policies.md) in Azure Active Directory (Azure AD) B2C. The information in this tutorial helps you to learn how to [customize the user interface (UI)](customize-ui-overview.md) of these experiences using your own HTML and CSS files. |
| 19 | + |
| 20 | +In this article, you learn how to: |
| 21 | + |
| 22 | +> [!div class="checklist"] |
| 23 | +> * Create UI customization files |
| 24 | +> * Create a sign-up and sign-in policy that uses the files |
| 25 | +> * Test the customized UI |
| 26 | +
|
| 27 | +If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 28 | + |
| 29 | +## Prerequisites |
| 30 | + |
| 31 | +If you haven't already created your own [Azure AD B2C Tenant](tutorial-create-tenant.md), create one now. You can use an existing tenant if you created one in a previous tutorial. |
| 32 | + |
| 33 | +## Create customization files |
| 34 | + |
| 35 | +You create an Azure storage account and container and then place basic HTML and CSS files in the container. |
| 36 | + |
| 37 | +### Create a storage account |
| 38 | + |
| 39 | +Although you can store your files in many ways, for this tutorial, you store them in [Azure Blob storage](../storage/blobs/storage-blobs-introduction.md). |
| 40 | + |
| 41 | +1. Make sure you're using the directory that contains your Azure subscription. Select the **Directory and subscription filter** in the top menu and choose the directory that contains your subscription. This directory is different than the one that contains your Azure B2C tenant. |
| 42 | + |
| 43 | +  |
| 44 | + |
| 45 | +2. Choose All services in the top-left corner of the Azure portal, search for and select **Storage accounts**. |
| 46 | +3. Select **Add**. |
| 47 | +4. Under **Resource group**, select **Create new**, enter a name for the new resource group, and then click **OK**. |
| 48 | +5. Enter a name for the storage account. The name you choose must be unique across Azure, must be between 3 and 24 characters in length, and may contain numbers and lowercase letters only. |
| 49 | +6. Select the location of the storage account or accept the default location. |
| 50 | +7. Accept all other default values, select **Review + create**, and then click **Create**. |
| 51 | +8. After the storage account is created, select **Go to resource**. |
| 52 | + |
| 53 | +### Create a container |
| 54 | + |
| 55 | +1. On the overview page of the storage account, select **Blobs**. |
| 56 | +2. Select **Container**, enter a name for the container, choose **Blob (anonymous read access for blobs only)**, and then click **OK**. |
| 57 | + |
| 58 | +### Enable CORS |
| 59 | + |
| 60 | + Azure AD B2C code in a browser uses a modern and standard approach to load custom content from a URL that you specify in a policy. Cross-origin resource sharing (CORS) allows restricted resources on a web page to be requested from other domains. |
| 61 | + |
| 62 | +1. In the menu, select **CORS**. |
| 63 | +2. For **Allowed origins**, **Allowed headers**, and **Exposed headers**, enter `your-tenant-name.b2clogin.com`. Replace `your-tenant-name` with the name of your Azure AD B2C tenant. For example, `fabrikam.b2clogin.com`. |
| 64 | +3. For **Allowed verbs**, select both `GET` and `OPTIONS`. |
| 65 | +4. For **Max age**, enter 200. |
| 66 | + |
| 67 | +  |
| 68 | + |
| 69 | +5. Click **Save**. |
| 70 | + |
| 71 | +### Create the customization files |
| 72 | + |
| 73 | +To customize the UI of the sign-up experience, you start by creating a simple HTML and CSS file. You can configure your HTML any way you want, but it must have a **div** element with an identifier of `api`. For example, `<div id="api"></div>`. Azure AD B2C injects elements into the `api` container when the page is displayed. |
| 74 | + |
| 75 | +1. In a local folder, create the following file and make sure that you change `your-storage-account` to the name of the storage account and `your-container` to the name of the container that you created. For example, `https://store1.blob.core.windows.net/b2c/style.css`. |
| 76 | + |
| 77 | + ```html |
| 78 | + <!DOCTYPE html> |
| 79 | + <html> |
| 80 | + <head> |
| 81 | + <title>My B2C Application</title> |
| 82 | + <link rel="stylesheet" href="https://your-storage-account.blob.core.windows.net/your-container/style.css"> |
| 83 | + </head> |
| 84 | + <body> |
| 85 | + <h1>My B2C Application</h1> |
| 86 | + <div id="api"></div> |
| 87 | + </body> |
| 88 | + </html> |
| 89 | + ``` |
| 90 | + |
| 91 | + The page can be designed any way that you want, but the **api** div element is required for any HTML customization file that you create. |
| 92 | + |
| 93 | +3. Save the file as *custom-ui.html*. |
| 94 | +4. Create the following simple CSS that centers all elements on the sign-up or sign-in page including the elements that Azure AD B2C injects. |
| 95 | + |
| 96 | + ```css |
| 97 | + h1 { |
| 98 | + color: blue; |
| 99 | + text-align: center; |
| 100 | + } |
| 101 | + .intro h2 { |
| 102 | + text-align: center; |
| 103 | + } |
| 104 | + .entry { |
| 105 | + width: 300px ; |
| 106 | + margin-left: auto ; |
| 107 | + margin-right: auto ; |
| 108 | + } |
| 109 | + .divider h2 { |
| 110 | + text-align: center; |
| 111 | + } |
| 112 | + .create { |
| 113 | + width: 300px ; |
| 114 | + margin-left: auto ; |
| 115 | + margin-right: auto ; |
| 116 | + } |
| 117 | + ``` |
| 118 | + |
| 119 | +5. Save the file as *style.css*. |
| 120 | + |
| 121 | +### Upload the customization files |
| 122 | + |
| 123 | +In this tutorial, you store the files that you created in the storage account so that Azure AD B2C can access them. |
| 124 | + |
| 125 | +1. Choose **All services** in the top-left corner of the Azure portal, search for and select **Storage accounts**. |
| 126 | +2. Select the storage account you created, select **Blobs**, and then select the container that you created. |
| 127 | +3. Select **Upload**, navigate to and select the *custom-ui.html* file, and then click **Upload**. |
| 128 | + |
| 129 | +  |
| 130 | + |
| 131 | +4. Copy the URL for the file that you uploaded to use later in the tutorial. |
| 132 | +5. Repeat step 3 and 4 for the *style.css* file. |
| 133 | + |
| 134 | +## Create a sign-up and sign-in policy |
| 135 | + |
| 136 | +To complete the steps in this tutorial, you need to create a test application and a sign-up or sign-in policy in Azure AD B2C. You can apply the principles described in this tutorial to the other user experiences, such as profile editing. |
| 137 | + |
| 138 | +### Create an Azure AD B2C application |
| 139 | + |
| 140 | +Communication with Azure AD B2C occurs through an application that you create in your tenant. The following steps create an application that redirects the authorization token that is returned to [https://jwt.ms](https://jwt.ms). |
| 141 | + |
| 142 | +1. Sign in to the [Azure portal](https://portal.azure.com). |
| 143 | +2. Make sure you're using the directory that contains your Azure AD B2C tenant by clicking the **Directory and subscription filter** in the top menu and choosing the directory that contains your tenant. |
| 144 | +3. Choose **All services** in the top-left corner of the Azure portal, and then search for and select **Azure AD B2C**. |
| 145 | +4. Select **Applications**, and then select **Add**. |
| 146 | +5. Enter a name for the application, for example *testapp1*. |
| 147 | +6. For **Web App / Web API**, select `Yes`, and then enter `https://jwt.ms` for the **Reply URL**. |
| 148 | +7. Click **Create**. |
| 149 | + |
| 150 | +### Create the policy |
| 151 | + |
| 152 | +To test your customization files, you create a built-in sign-up or sign-in policy that uses the application that you previously created. |
| 153 | + |
| 154 | +1. In your Azure AD B2C tenant, select **Sign-up or sign-in policies**, and then click **Add**. |
| 155 | +2. Enter a name for the policy. For example, *signup_signin*. The prefix *B2C_1* is automatically added to the name when the policy is created. |
| 156 | +3. Select **Identity providers**, set **Email sign-up** for a local account, and then click **OK**. |
| 157 | +4. Select **Sign-up attributes**, choose the attributes that you want to collect from the customer during sign-up. For example, set **Country/Region**, **Display Name**, and **Postal Code**, and then click **OK**. |
| 158 | +5. Select **Application claims**, choose the claims that you want returned in the authorization tokens sent back to your application after a successful sign-up or sign-in experience. For example, select **Display Name**, **Identity Provider**, **Postal Code**, **User is new** and **User's Object ID**, and then click **OK**. |
| 159 | +6. Select **Page UI customization**, select **Unified sign-up or sign-in page**, and the click **Yes** for **Use custom page**. |
| 160 | +7. In **Custom page URI**, enter the URL for the *custom-ui.html* file that you recorded earlier, and then click **OK**. |
| 161 | +8. Click **Create**. |
| 162 | + |
| 163 | +## Test the policy |
| 164 | + |
| 165 | +1. In your Azure AD B2C tenant, select **Sign-up or sign-in policies**, and then select the policy that you created. For example, *B2C_1_signup_signin*. |
| 166 | +2. Make sure that the application that you created is selected in **Select application**, and then click **Run Now**. |
| 167 | + |
| 168 | +  |
| 169 | + |
| 170 | + You should see a page similar to the following example with the elements centered based on the CSS file that you created: |
| 171 | + |
| 172 | +  |
| 173 | + |
| 174 | +## Next steps |
| 175 | + |
| 176 | +In this article, you learned how to: |
| 177 | + |
| 178 | +> [!div class="checklist"] |
| 179 | +> * Create UI customization files |
| 180 | +> * Create a sign-up and sign-in policy that uses the files |
| 181 | +> * Test the customized UI |
| 182 | + |
| 183 | +> [!div class="nextstepaction"] |
| 184 | +> [Language customization in Azure Active Directory B2C](active-directory-b2c-reference-language-customization.md) |
0 commit comments