Skip to content

Commit cdf40a5

Browse files
authored
Update 2025-02-07-okta-hosted-sign-in-widget.md
1 parent 7089410 commit cdf40a5

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

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

+24-8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ We're not here to change the button color or simply slap a logo on the widget; w
5353
We will accomplish this by utilizing standard Javascript and CSS.
5454
If you use the Okta-hosted widget, you will find it under **Customizations** > **Brands** > **[your custom brand]** > **Pages** > **Sign-in** page. Click the **Configure** button and toggle the **Code editor** to **ON**. At this point, you should see some code appear like the one below:
5555

56+
{% raw %}
5657
```html
5758
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
5859
<html>
@@ -104,6 +105,7 @@ If you use the Okta-hosted widget, you will find it under **Customizations** > *
104105
</body>
105106
</html>
106107
```
108+
{% endraw %}
107109

108110
Let's make a note of a few key things:
109111
- `OktaUtil` is a global object that contains all of the widget methods and settings
@@ -115,6 +117,7 @@ If you want more fine-grained control over the widget's appearance, Okta allows
115117

116118
Within the `<head>` section and below the following code,
117119

120+
{% raw %}
118121
```html
119122
<!-- Favicon from theme -->
120123
<link rel="shortcut icon" href="{{faviconUrl}}" type="image/x-icon"/>
@@ -125,9 +128,11 @@ insert the following code that points to the Font Awesome library, which is host
125128
```css
126129
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css">
127130
```
131+
{% endraw %}
128132

129133
Next, let's add some general styles to achieve the desired look. Just below the following block of code,
130134

135+
{% raw %}
131136
```html
132137
<title>{{pageTitle}}</title>
133138
{{{SignInWidgetResources}}}
@@ -138,6 +143,7 @@ Next, let's add some general styles to achieve the desired look. Just below the
138143
}
139144
</style>
140145
```
146+
{% endraw %}
141147

142148
add the following code,
143149

@@ -506,13 +512,16 @@ Still, within the `<head>` section, and just below the code above, insert the fo
506512
## Changing the layout of the Okta Sign-In Widget
507513
We must modify the page's core HTML to make the widget layout horizontal and achieve the desired effect. Replace the default widget code:
508514

515+
{% raw %}
509516
```html
510517
<div id="login-bg-image-id" class="login-bg-image tb--background"></div>
511518
<div id="okta-login-container"></div>
512519
```
520+
{% endraw %}
513521

514522
With the following code:
515523

524+
{% raw %}
516525
```html
517526
<!-- custom login -->
518527
<div class="container" id="container">
@@ -544,6 +553,7 @@ With the following code:
544553
</div>
545554
<!-- end custom login -->
546555
```
556+
{% endraw %}
547557

548558
## Enhancing the experience with Okta Custom Sign-In Widget
549559
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!
@@ -555,16 +565,20 @@ To manipulate the pieces of the widget, we need to know what those HTML elements
555565
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.
556566

557567
Below the OktaUtil object,
568+
569+
{% raw %}
558570
```html
559571
<!--
560572
"OktaUtil" defines a global OktaUtil object
561573
that contains methods used to complete the Okta login flow.
562574
-->
563575
{{{OktaUtil}}}
564576
```
577+
{% endraw %}
565578

566-
Add the following code:
579+
Add the following code:
567580

581+
{% raw %}
568582
```html
569583
<!-- Let's add a reference to jQuery for easy object manipulation. You do not have to do this, you can use vanila JS instead -->
570584

@@ -575,14 +589,14 @@ Add the following code:
575589
PLEASE SEE THE FOLLOWING LINK: https://developer.okta.com/docs/guides/custom-widget-gen3/main/
576590
*****/
577591
578-
// 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
592+
// 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
579593
console.log("OKTAUTIL object: ", OktaUtil);
580594
581-
// get request context - this allows us to get access to any data that was passed in the /authorize request...see BONUS CODE section later for a sample code
595+
// get request context - this allows us to get access to any data that was passed in the /authorize request...see the BONUS CODE section later for a sample code
582596
var requestContext = OktaUtil.getRequestContext();
583597
console.log("REQUEST CONTEXT: ",requestContext);
584598
585-
// "config" object contains default widget configuration
599+
// "config" object contains the default widget configuration
586600
// with any custom overrides defined in your admin settings.
587601
var config = OktaUtil.getSignInWidgetConfig();
588602
console.log("CONFIG object: ", config);
@@ -626,7 +640,7 @@ Add the following code:
626640
{type: 'Microsoft', id: '[ID OF YOUR MICROSOFT IDP FROM OKTA]'}
627641
];
628642
629-
// display the social buttons first, before the username/password form
643+
// display the social buttons before the username/password form
630644
config.idpDisplay ="PRIMARY";
631645
632646
// enable registration
@@ -640,13 +654,13 @@ Add the following code:
640654
OktaUtil.completeLogin,
641655
function(error) {
642656
// Logs errors that occur when configuring the widget.
643-
// Remove or replace this with your own custom error handler if desired.
657+
// Remove or replace this with your custom error handler if desired.
644658
console.log(error.message, error);
645659
}
646660
);
647661
648662
// Initialize another Okta widget object and Bootstrap into the Signup part...
649-
// this is needed so we can flip between login and registration as only one instance can be rendered at a time.
663+
// This is needed to flip between login and registration, as only one instance can be rendered at a time.
650664
var oktaSignUp = new OktaSignIn({
651665
issuer: config.baseUrl,
652666
flow: 'signup'
@@ -726,6 +740,8 @@ Add the following code:
726740
};
727741
</script>
728742
```
743+
{% endraw %}
744+
729745
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.
730746

731747
## Content Security Policy to allow trusted external resources
@@ -755,6 +771,6 @@ For more examples of customizing the Okta Sign-In Widget check out these blogs a
755771
- [A Secure and Themed Sign-in Page](blog/2023/01/12/signin-custom-domain#set-up-the-angular-micro-frontend-site-and-add-okta)
756772
- [i18n in Java 11, Spring Boot, and JavaScript](blog/2019/02/25/java-i18n-internationalization-localization)
757773
- [Style the Sign-In page](https://developer.okta.com/docs/guides/custom-widget/main/#modify-the-css)
758-
- [Awesome Login CSS Customization!(feat. Amy Kapers)](https://www.youtube.com/watch?v=Q__ugprsOWo)
774+
- [Awesome Login CSS Customization! (feat. Amy Kapers)](https://www.youtube.com/watch?v=Q__ugprsOWo)
759775

760776
And to learn more content on ways you can customize your app's login experience, follow us @OktaDev on [X](https://twitter.com/oktadev) and subscribe to our [YouTube channel](https://www.youtube.com/c/OktaDev/)! We also want to hear from you about topics you want to see and questions you may have so please leave us a comment below!

0 commit comments

Comments
 (0)