AD FS provides several options for administrators to customize and tailor the end-user experience to meet their corporate needs. The following article will serve as a walkthrough for modifying the look, feel and steps to enable advanced customization using JavaScript for AD FS Sign-in and Password Update page.
AD FS in Windows Server provides built-in support for customizing the sign-in experience. For a majority of these scenarios, the built-in Windows PowerShell cmdlets are all that is required. In some cases, AD FS administrators may want to provide additional sign-in experiences that are not possible through the existing PowerShell commands that ship in-box with AD FS. In certain instances, it is feasible for administrators to customize the sign-in experience further by adding additional logic to onload.js that is provided by AD FS and will be executed on all the AD FS pages.
Customizing the AD FS experience by using onload.js
The theme that is shipped out-of-the-box is called Default. Export the default theme. The following cmdlet creates a custom web theme, which duplicates the default web theme
- New-AdfsWebTheme –Name custom –SourceName default
To export the theme, use the following cmdlet. Locate onload.js under the script folder in the directory that is specified in the export cmdlet and add the custom logic to the script.
- Export-AdfsWebTheme –Name default –DirectoryPath c:\theme
Update the theme with the modified onload.js. Use the following cmdlet to apply the update onload.js to a custom web theme.
For AD FS on Windows Server 2012 R2:
- Set-AdfsWebTheme -TargetName custom -AdditionalFileResource @{Uri='/adfs/portal/script/onload.js';path="c:\theme\script\onload.js"}
For AD FS on Windows Server 2016:
- Set-AdfsWebTheme -TargetName custom -AdditionalFileResource @{Uri='/adfs/portal/script/onload.js';path="c:\theme\script\onload.js"}
Apply the custom web theme to AD FS using the following cmdlet.
- Set-AdfsWebConfig -ActiveThemeName custom
Additional Customization samples
Consider the below code snippet to accept SAM-account name as a login format on an AD FS form for Sign in and Update password page, the complete code is attached within the article. The original onload.js, the one that comes with the default web theme will execute on all ADFS pages and hence always make sure that proper logic to distinguish the current page context is handled.
Sign in Page
- if (typeof Login != 'undefined'){
- Login.submitLoginRequest = function () {
- var u = new InputUtil();
- var e = new LoginErrors();
- var userName = document.getElementById(Login.userNameInput);
- var password = document.getElementById(Login.passwordInput);
- if (userName.value && !userName.value.match('[@\\\\]'))
- {
- var userNameValue = 'contoso.com\\' + userName.value; // replace contoso.com with custom ADFS Name
- document.forms['loginForm'].UserName.value = userNameValue;
- }
-
- if (!userName.value) {
- u.setError(userName, e.userNameFormatError);
- return false;
- }
-
- if (!password.value)
- {
- u.setError(password, e.passwordEmpty);
- return false;
- }
- document.forms['loginForm'].submit();
- return false;
- };
- }