Skip to content

Commit 2542c63

Browse files
authored
Update 2025-02-24-okta-hosted-sign-in-widget.md
1 parent 4b896a7 commit 2542c63

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

_source/_posts/2025-02-24-okta-hosted-sign-in-widget.md

+25-24
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tweets:
1212
- ""
1313
image: blog/okta-hosted-sign-in-widget/sign-in-widget-social-image.jpeg
1414
type: conversion
15+
github: https://github.com/oktadev/okta-hosted-sign-in-widget
1516
---
1617
The Okta Sign-In Widget is a powerful tool that allows developers to integrate Okta authentication into their web applications seamlessly. But did you know you can also customize the widget's look and feel to match your application's design, even if hosted on Okta? Whether you want to modify colors, add custom branding, or adjust the layout, Okta provides flexibility to make the widget fit your brand's identity.
1718

@@ -130,7 +131,7 @@ insert the following code that points to the Font Awesome library, which is host
130131
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css">
131132
```
132133

133-
Next, let's add some general styles to achieve the desired look. Within the `<style>...</style>` ,
134+
Next, let's add some general styles to achieve the desired look. Within the `<style>...</style>` block,
134135

135136
{% raw %}
136137
```html
@@ -623,11 +624,11 @@ With the following code:
623624
## Enhancing the experience with Okta Custom Sign-In Widget
624625
Now, let's get into the meat and potatoes. We first need to hide some unwanted pieces of the widget (logo, header, links, etc.). Then, we must apply CSS to the existing HTML objects by replacing the classes (e.g., making the social button round). Easier said than done!
625626

626-
To manipulate the pieces of the widget, we need to know what those HTML elements are and to find out; you can utilize the developer tools of the browser you are using. After figuring out what CSS classes and objects I needed to modify, I created the following code. So replace the entire default `<script>` section of the widget with the code below. I commented on almost every line; there is A LOT, but it'll make this step straightforward. There is one **IMPORTANT** piece of information to note. It is in the comments, but I will call it out here.
627+
To manipulate the pieces of the widget, we need to know what those HTML elements are, and to find out, you can utilize the developer tools of the browser you are using. After figuring out what CSS classes and objects I needed to modify, I created the following code. So, replace the widget's default `<script>` section with the code below. I commented on almost every line; there is A LOT, but it'll make this step straightforward. There is one **IMPORTANT** piece of information to note. It is in the comments, but I will call it out here.
627628

628629
>**IMPORTANT**: Setting the Routing Rule in the admin interface for external IdPs will break this code, so instead, set the identity providers here in the config object.
629630
630-
Additionally, I've included some extra code to showcase how you can style or manipulate the widget based on the client id, making per application customizations possible.
631+
Additionally, I've included some extra code to showcase how you can style or manipulate the widget based on the client id, making per-application customizations possible.
631632

632633
Below the OktaUtil object,
633634

@@ -645,15 +646,15 @@ Add the following code:
645646

646647
{% raw %}
647648
```html
648-
<!-- Let's add a reference to JQuery for easy object manipulation. You do not have to do this, you can use vanila JS instead -->
649+
<!-- Let's add a reference to JQuery for easy object manipulation. You do not have to do this; you can use vanila JS instead -->
649650
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
650651
<script type="text/javascript" nonce="{{nonceValue}}">
651652
/*****
652653
FOR IMPORTANT DETAILS ABOUT MODIFYING THE WIDGET IF YOU ARE USING THE V3,
653654
PLEASE SEE THE FOLLOWING LINK: https://developer.okta.com/docs/guides/custom-widget-gen3/main/
654655
*****/
655656
656-
// if you are interested in seeing what all is in the setttings object log it here and use your browser's dev tools to look at it
657+
//If you are interested in seeing what all is in the settings object log it here and use your browser's dev tools to look at it
657658
console.log("OKTAUTIL object: ", OktaUtil);
658659
659660
// get request context - this allows us to get access to any data that was passed in the /authorize request...see BONUS CODE section later on for a sample code
@@ -692,9 +693,9 @@ Add the following code:
692693
}
693694
/****** END BONUS CODE ******/
694695
695-
// You can either create a Routing Rule to enable external IdPs or you can set the identity providers here in the config object
696-
// I have mine set up in the Okta Admin console via Routing Rule but here is the code if you'd like to set them here
697-
// To learn how to set up external idps in your Okta tenant visit this link:
696+
// You can either create a Routing Rule to enable external IdPs, or you can set the identity providers here in the config object
697+
// I have mine set up in the Okta Admin console via Routing Rule, but here is the code if you'd like to set them here
698+
// To learn how to set up external IdPs in your Okta tenant, visit this link:
698699
// https://developer.okta.com/docs/guides/identity-providers/#social-logins
699700
700701
config.idps = [
@@ -716,13 +717,13 @@ Add the following code:
716717
OktaUtil.completeLogin,
717718
function(error) {
718719
// Logs errors that occur when configuring the widget.
719-
// Remove or replace this with your own custom error handler if desired.
720+
// Remove or replace this with your custom error handler if desired.
720721
console.log(error.message, error);
721722
}
722723
);
723724
724725
// Initialize another Okta widget object and bootstrap into the Signup part...
725-
// this is needed so we can flip between login and registration as only one instance can be rendered at a time.
726+
//This is needed so we can flip between login and registration, as only one instance can be rendered at a time.
726727
var oktaSignUp = new OktaSignIn({
727728
issuer: config.baseUrl,
728729
flow: 'signup'
@@ -734,7 +735,7 @@ Add the following code:
734735
manipulateObjects();
735736
});
736737
737-
// make the panels move left-right to show/hide the login and reg forms
738+
// Make the panels move left-right to show/hide the login and reg forms
738739
const signUpButton = document.getElementById('signUp');
739740
const signInButton = document.getElementById('signIn');
740741
const container = document.getElementById('container');
@@ -758,40 +759,40 @@ Add the following code:
758759
//console.log("Trying to manipulate the widget...");
759760
760761
// Depending on the config, footer contains links for sign-up, "Forgot password", "Back to Sign in" and possibly
761-
// other self-service options. We'll hide the sign-up option since we're dealing with it separately but will leave the rest.
762-
// If you did want to hide it entirely you can use the following code, you can either hide the entire footer or just the pieces of it
762+
// other self-service options. We'll hide the sign-up option since we're dealing with it separately, but we will leave the rest.
763+
// If you did want to hide it entirely, you can use the following code, you can either hide the entire footer or just the pieces of it
763764
// $("div.siw-main-footer").css("display","none");
764765
$("div.auth-footer div.signup-info").css("display","none");
765766
766-
// same for the header, let's hide it
767+
// Same for the header; let's hide it
767768
$("div.okta-sign-in-header").css("display","none");
768769
769-
// we want to add the placeholder for the username which is in the email format for my Okta tenant
770+
// We want to add the placeholder for the username, which is in the email format for my Okta tenant
770771
$("input[name='identifier']").attr('placeholder', 'Email');
771772
$("input[name='userProfile.email']").attr('placeholder', 'Email');
772773
773774
/******* TRANSFORM SOCIAL BUTTONS **************/
774-
// we need the social buttons to look completely different from the default ones, we will make use of the FontAwesome library for icons
775+
// We need the social buttons to look completely different from the default ones, we will make use of the FontAwesome library for icons
775776
$("#okta-login-container div.okta-idps-container").wrapAll('<div class="social-container">');
776777
777-
// modify the google button
778+
// Modify the google button
778779
$("a[data-se='social-auth-google-button']").html('<i class="fab fa-google-plus-g"></i>');
779780
$("a[data-se='social-auth-google-button']").removeClass();
780781
$("a[data-se='social-auth-google-button']").addClass('social');
781782
782-
// modify the microsoft button
783+
// Modify the microsoft button
783784
$("a[data-se='social-auth-microsoft-button']").html('<i class="fab fa-microsoft"></i>');
784785
$("a[data-se='social-auth-microsoft-button']").removeClass();
785786
$("a[data-se='social-auth-microsoft-button']").addClass('social');
786787
/********* END TRANSFORM SOCIAL BUTTONS ************/
787788
788-
// if a user is trying to access Okta dashboard or they came here by some other means, hide the reg form and social buttons. Please keep in mind, this is merely hiding the reg form via frontend (js/css), if the user is crafty they could still access the form
789+
//If a user is trying to access the Okta dashboard or came here by other means, hide the reg form and social buttons. Please remember that this merely hides the reg form via frontend (js/css). If the user is crafty, they could still access the form
789790
if(clientid == ["CLIENT ID OF YOUR OKTA DASHBOARD APP"]){
790-
// hide the registration panel
791+
// Hide the registration panel
791792
$("#reg-overlay").css("display","none");
792-
// display the text if this is an Admin user trying to access the dashboard
793+
// Display the text if this is an Admin user trying to access the dashboard
793794
$("#admin-overlay").css("display","flex");
794-
// hide the social buttons container
795+
// Hide the social buttons container
795796
$("#okta-login-container div.sign-in-with-idp").css("display","none");
796797
}
797798
@@ -804,7 +805,7 @@ Add the following code:
804805
Feel free to preview your work by clicking the **Save to draft** button and then the **Preview** button at the top, but just know there is one last step before we can see the final result.
805806

806807
## Content Security Policy to allow trusted external resources
807-
The remaining task to do is to customize the default Content Security Policy (CSP) to allow trusted external resources and prevent violations. This will enable us to use external resources, such as the Font Awesome library, Google Fonts, and jQuery. You must add the URLs in the CSP if you use additional libraries or resources.
808+
The remaining task is to customize the default Content Security Policy (CSP) to allow trusted external resources and prevent violations. This will enable us to use external resources, such as the Font Awesome library, Google Fonts, and jQuery. You must add the URLs in the CSP if you use additional libraries or resources.
808809

809810
>**SECURE BEST PRACTICE**:
810811
- ✅ Remember to use trusted, well-maintained libraries, and pin specific versions you've used for future reference and troubleshooting issues.
@@ -819,7 +820,7 @@ CSP is located under the **Settings** tab on the **Sign-in page** section, **Cus
819820
And that should be all! After you've added the necessary CSP information and have previewed your sign-in page, you can now click the **Publish** button under the **Page Design** tab to see your changes live. If you copied/pasted everything correctly, you should now have a sign-in widget that looks and functions like the one showcased at the beginning of this tutorial.
820821

821822
## Troubleshooting your Okta hosted sign in widget
822-
Before publishing live to production be sure to test on your preview org or developer org first. To target specific elements/attributes, you can refer to this [Okta doc on modifying CSS](https://developer.okta.com/docs/guides/custom-widget/main/#modify-the-css).
823+
Before publishing live to production, be sure to test it on your preview org or developer org first. To target specific elements/attributes, refer to this [Okta doc on modifying CSS](https://developer.okta.com/docs/guides/custom-widget/main/#modify-the-css).
823824

824825
## More ways to customize your sign-in page
825826
The manipulation and styling were only done for login and registration. As bonus practice, I suggest you try to modify the MFA screens. To recap what I have demonstrated, customizing the Okta Sign-In Widget allows you to make authentication an integrated part of your app's user experience. From simple color changes to more complex UI tweaks, Okta's flexibility allows you to maintain your brand's visual identity while ensuring a secure and seamless login process.

0 commit comments

Comments
 (0)