author | ms.service | ms.subservice | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|
msmimart |
active-directory-b2c |
B2C |
include |
03/19/2020 |
mimart |
By using the page UI customization feature, you can customize the look and feel of any custom policy. You can also maintain brand and visual consistency between your application and Azure AD B2C.
Azure AD B2C runs code in your customer's browser by using Cross-Origin Resource Sharing (CORS). At runtime, content is loaded from a URL you specify in your user flow or custom policy. Each page in the user experience loads its content from the URL you specify for that page. After content is loaded from your URL, it's merged with an HTML fragment inserted by Azure AD B2C, and then the page is displayed to your customer.
Create an HTML page with your own branding to serve your custom page content. This page can be a static *.html
page, or a dynamic page like .NET, Node.js, or PHP.
Your custom page content can contain any HTML elements, including CSS and JavaScript, but cannot include insecure elements like iframes. The only required element is a div element with id
set to api
, such as this one <div id="api"></div>
within your HTML page.
<!DOCTYPE html>
<html>
<head>
<title>My Product Brand Name</title>
</head>
<body>
<div id="api"></div>
</body>
</html>
Instead of creating your custom page content from scratch, you can customize Azure AD B2C's default page content.
The following table lists the default page content provided by Azure AD B2C. Download the files and use them as a starting point for creating your own custom pages.
Default page | Description | Content definition ID (custom policy only) |
---|---|---|
exception.html | Error page. This page is displayed when an exception or an error is encountered. | api.error |
selfasserted.html | Self-Asserted page. Use this file as a custom page content for a social account sign-up page, a local account sign-up page, a local account sign-in page, password reset, and more. The form can contain various input controls, such as: a text input box, a password entry box, a radio button, single-select drop-down boxes, and multi-select check boxes. | api.localaccountsignin, api.localaccountsignup, api.localaccountpasswordreset, api.selfasserted |
multifactor-1.0.0.html | Multi-factor authentication page. On this page, users can verify their phone numbers (by using text or voice) during sign-up or sign-in. | api.phonefactor |
updateprofile.html | Profile update page. This page contains a form that users can access to update their profile. This page is similar to the social account sign-up page, except for the password entry fields. | api.selfasserted.profileupdate |
unified.html | Unified sign-up or sign-in page. This page handles the user sign-up and sign-in process. Users can use enterprise identity providers, social identity providers such as Facebook or Google+, or local accounts. | api.signuporsignin |
When using your own HTML and CSS files to customize the UI, host your UI content on any publicly available HTTPS endpoint that supports CORS. For example, Azure Blob storage, Azure App Services, web servers, CDNs, AWS S3, or file sharing systems.
- Use an absolute URL when you include external resources like media, CSS, and JavaScript files in your HTML file.
- Using page layout version 1.2.0 and above, you can add the
data-preload="true"
attribute in your HTML tags to control the load order for CSS and JavaScript. Withdata-preload=true
, the page is constructed before being shown to the user. This attribute helps prevent the page from "flickering" by preloading the CSS file, without the un-styled HTML being shown to the user. The following HTML code snippet shows the use of thedata-preload
tag.<link href="https://path-to-your-file/sample.css" rel="stylesheet" type="text/css" data-preload="true"/>
- We recommend that you start with the default page content and build on top of it.
- You can include JavaScript in your custom content for both user flows and custom policies.
- Supported browser versions are:
- Internet Explorer 11, 10, and Microsoft Edge
- Limited support for Internet Explorer 9 and 8
- Google Chrome 42.0 and above
- Mozilla Firefox 38.0 and above
- Safari for iOS and macOS, version 12 and above
- Due to security restrictions, Azure AD B2C doesn't support
frame
,iframe
, orform
HTML elements.
Here's an overview of the process:
- Prepare a location to host your custom page content (a publicly accessible, CORS-enabled HTTPS endpoint).
- Download and customize a default page content file, for example
unified.html
. - Publish your custom page content your publicly available HTTPS endpoint.
- Set cross-origin resource sharing (CORS) for your web app.
- Point your policy to your custom policy content URI.
Create a custom page content with your product's brand name in the title.
-
Copy the following HTML snippet. It is well-formed HTML5 with an empty element called <div id="api"></div> located within the <body> tags. This element indicates where Azure AD B2C content is to be inserted.
<!DOCTYPE html> <html> <head> <title>My Product Brand Name</title> </head> <body> <div id="api"></div> </body> </html>
-
Paste the copied snippet in a text editor, and then save the file as customize-ui.html.
Note
HTML form elements will be removed due to security restrictions if you use login.microsoftonline.com. If you want to use HTML form elements in your custom HTML content, use b2clogin.com.
In this article, we use Azure Blob storage to host our content. You can choose to host your content on a web server, but you must enable CORS on your web server.
To host your HTML content in Blob storage, perform the following steps:
- Sign in to the Azure portal.
- On the Hub menu, select New > Storage > Storage account.
- Select a Subscription for your storage account.
- Create a Resource group or select an existing one.
- Enter a unique Name for your storage account.
- Select the Geographic location for your storage account.
- Deployment model can remain Resource Manager.
- Performance can remain Standard.
- Change Account Kind to Blob storage.
- Replication can remain RA-GRS.
- Access tier can remain Hot.
- Select Review + create to create the storage account. After the deployment is completed, the Storage account page opens automatically.
To create a public container in Blob storage, perform the following steps:
- Under Blob service in the left-hand menu, select Blobs.
- Select +Container.
- For Name, enter root. The name can be a name of your choosing, for example contoso, but we use root in this example for simplicity.
- For Public access level, select Blob, then OK.
- Select root to open the new container.
- Select Upload.
- Select the folder icon next to Select a file.
- Navigate to and select customize-ui.html, which you created earlier in the Page UI customization section.
- If you want to upload to a subfolder, expand Advanced and enter a folder name in Upload to folder.
- Select Upload.
- Select the customize-ui.html blob that you uploaded.
- To the right of the URL text box, select the Copy to clipboard icon to copy the URL to your clipboard.
- In web browser, navigate to the URL you copied to verify the blob you uploaded is accessible. If it is inaccessible, for example if you encounter a
ResourceNotFound
error, make sure the container access type is set to blob.
Configure Blob storage for Cross-Origin Resource Sharing by performing the following steps:
- In the menu, select CORS.
- For Allowed origins, enter
https://your-tenant-name.b2clogin.com
. Replaceyour-tenant-name
with the name of your Azure AD B2C tenant. For example,https://fabrikam.b2clogin.com
. Use all lowercase letters when entering your tenant name. - For Allowed Methods, select both
GET
andOPTIONS
. - For Allowed Headers, enter an asterisk (*).
- For Exposed Headers, enter an asterisk (*).
- For Max age, enter 200.
- Select Save.
Validate that you're ready by performing the following steps:
- Repeat the configure CORS step. For Allowed origins, enter
https://www.test-cors.org
- Navigate to www.test-cors.org
- For the Remote URL box, paste the URL of your HTML file. For example,
https://your-account.blob.core.windows.net/azure-ad-b2c/unified.html
- Select Send Request.
The result should be
XHR status: 200
. If you receive an error, make sure that your CORS settings are correct. You might also need to clear your browser cache or open an in-private browsing session by pressing Ctrl+Shift+P.