Keycloak Modal Login and Login Page Customization

2,078 views
Skip to first unread message

Matteo Riva

unread,
Sep 26, 2022, 10:29:03 AM9/26/22
to Keycloak User
Hello everyone,

I hope it is not a too complex task, but I would like to add a modal login function to my login page in Keycloak.
In summary, I would like to add these windows "Login" and "Register"...

Modal_login47.PNG

...to this:

keycloak_login.PNG

Instead of "Login" and "Register" windows, I would like to change them to "Link1" and "Link2", for example. The idea is that: if I click "Link1", then Keycloak let me login in "Link1" and the same thing for "Link2". Is it possible? If yes, how?
Last question: how can I change the dark background in Keycloak login page?

Can you help me please?
Thank you so much in advance!

Matteo

Matteo Riva

unread,
Sep 29, 2022, 9:14:11 AM9/29/22
to Keycloak User
UPDATE: I searched for something, but I could not find anything about "Modal login" in Keycloak or, at least, how to customize the login page in order to have those windows. Anyone here has an idea? A suggestion? Please!
For the Login page customization, I found this site:


And I am trying to work with it!

Matteo

Matteo Riva

unread,
Oct 6, 2022, 5:23:36 AM10/6/22
to Keycloak User
UPDATE 2: After following the first steps of the site I cited in the previous message, I get this error:

Internal Server Error

And the page is completely blank. 
In summary, after I create the new folder "login" in "custom" and if I subsequently select "custom" from Themes....
admin_console.png

....and I reload the page, it seems Keycloak does not read the login page in a correct way anymore. I will try it again in order to see if I can fix it in some way.
Anyone could tell me if you succeeded in changing your login page, please? If yes, how you did it? Do you know how to add the two windows I said in my first message?

Please, any help would be so appreciated! Thank you so much.

Matteo

Matteo Riva

unread,
Oct 11, 2022, 9:13:18 AM10/11/22
to Keycloak User
UPDATE 3: Starting from the tutorial I cited before (https://www.baeldung.com/keycloak-custom-login-page), I finally succeeded in having this login page:

keycloak_login_custom.PNG

The issues now are three:

Number 1:

Following the tutorial, I changed the background color (light blue) in login/resources/css/login.css. Now I would like to change the background color to white or anything else. I tried to restore the css file and I tried this line too:

.login-pf body { background: #ffffff; background-size: cover; height: 100%; } 

But nothing has changed at all!! Why? I am doing the same steps I did when I put that light blue color in the background. Now I cannot change it anymore....

Number 2:

I would like to add an image outside the "sign in white square". How can I do it? Always following the tutorial, I change the end of the template.ftl  file by adding this line:

<img src="/opt/keycloak/themes/custom/login/resources/img/log.png" height="300px" width="500px"/>

I do not know why, but the image is not correctly taken and I can see only this:

errore_immagine.PNG

Number 3:

I would like to add buttons to the images "XNAT" and "REDCap", maybe with colored borders when I click them too, in order to distinguish when I click one or the other. Do you know how to do it? I tried by adding these lines to the template.ftl file:

<form class="column-xnat-redcap">
    <button style="height:95px;width:210px; float:left" onclick="add_frame()" href="http://**************" id="xnat">
         <img src="https://www.xnat.org/images/XNAT-logo-980.png" style="width: 200px; height: 90px; position:relative; left:-3px;" align="left" />
    </button>
    <button style="height:95px;width:210px; float:right" onclick="add_border()" href="http://****************" id="redcap">
         <img src="https://informatics.wustl.edu/wp-content/uploads/2018/04/redcap_logo_high_res.jpg" style="width: 200px; height: 90px; position:relative; left:3px; top: 0px;" align="right" />
    </button>
<script>
function add_frame(){

document.getElementById('xnat').style.border = "3px solid blue";

}

function add_border(){

document.getElementById('redcap').style.border = "3px solid red";

}
</script>

What I obtain are two buttons, which bring me to incorrect links of Keycloak. 

Any help would be so appreciated.
Thank you so much in advance.

Matteo

Matteo Riva

unread,
Oct 12, 2022, 3:35:49 AM10/12/22
to Keycloak User
UPDATE 4: I succeeded in fixing the problem "Number 3", but I keep on having some issue with "Number 1" and "Number 2".
Can you help me, please?

Thank you again.

Matteo

Matteo Riva

unread,
Oct 12, 2022, 8:13:43 AM10/12/22
to Keycloak User
UPDATE 5: I succeeded in solving the problem "Number 2", but I keep on having some issue with "Number 1". I tried to change the login.css file with different colors again, but nothing has changed.
I know, I am sorry for being a bit spamming, I just do not want you to waste any time.

Thank you again.

Matteo

David Cook

unread,
Oct 12, 2022, 6:49:42 PM10/12/22
to Matteo Riva, Keycloak User

Hey Matteo,

 

I think that I’ve had the same issue before, and I imagine that the problem is probably due to caching at some level.

 

First, try holding “Shift” and refresh in your browser to flush your browser cache.

 

Second, there is a theme cache that may need to be cleared:

https://github.com/keycloak/keycloak/discussions/8628

https://www.keycloak.org/docs/latest/server_development/#creating-a-theme

 

The right way to clear that cache will probably depend on your version.

 

David Cook

Senior Software Engineer

Prosentient Systems

Suite 7.03

6a Glen St

Milsons Point NSW 2061

Australia

 

Office: 02 9212 0899

Online: 02 8005 0595

 

From: keyclo...@googlegroups.com <keyclo...@googlegroups.com> On Behalf Of Matteo Riva
Sent: Wednesday, 12 October 2022 11:14 PM
To: Keycloak User <keyclo...@googlegroups.com>
Subject: [keycloak-user] Re: Keycloak Modal Login and Login Page Customization

 

UPDATE 5: I succeeded in solving the problem "Number 2", but I keep on having some issue with "Number 1". I tried to change the login.css file with different colors again, but nothing has changed.

I know, I am sorry for being a bit spamming, I just do not want you to waste any time.

 

Thank you again.

 

Matteo

Il giorno mercoledì 12 ottobre 2022 alle 09:35:49 UTC+2 Matteo Riva ha scritto:

UPDATE 4: I succeeded in fixing the problem "Number 3", but I keep on having some issue with "Number 1" and "Number 2".

Can you help me, please?

 

Thank you again.

 

Matteo

Il giorno martedì 11 ottobre 2022 alle 15:13:18 UTC+2 Matteo Riva ha scritto:

UPDATE 3: Starting from the tutorial I cited before (https://www.baeldung.com/keycloak-custom-login-page), I finally succeeded in having this login page:

 

 

The issues now are three:

 

Number 1:

 

Following the tutorial, I changed the background color (light blue) in login/resources/css/login.css. Now I would like to change the background color to white or anything else. I tried to restore the css file and I tried this line too:

 

.login-pf body { background: #ffffff; background-size: cover; height: 100%; } 

 

But nothing has changed at all!! Why? I am doing the same steps I did when I put that light blue color in the background. Now I cannot change it anymore....

 

Number 2:

 

I would like to add an image outside the "sign in white square". How can I do it? Always following the tutorial, I change the end of the template.ftl  file by adding this line:

 

<img src="/opt/keycloak/themes/custom/login/resources/img/log.png" height="300px" width="500px"/>

 

I do not know why, but the image is not correctly taken and I can see only this:

 

 

Number 3:

 

I would like to add buttons to the images "XNAT" and "REDCap", maybe with colored borders when I click them too, in order to distinguish when I click one or the other. Do you know how to do it? I tried by adding these lines to the template.ftl file:

 

<form class="column-xnat-redcap">
    <button style="height:95px;width:210px; float:left" onclick="add_frame()" href="http://**************" id="xnat">

         <img src="https://www.xnat.org/images/XNAT-logo-980.png" style="width: 200px; height: 90px; position:relative; left:-3px;" align="left" />
    </button>
    <button style="height:95px;width:210px; float:right" onclick="add_border()" href="http://****************" id="redcap">

         <img src="https://informatics.wustl.edu/wp-content/uploads/2018/04/redcap_logo_high_res.jpg" style="width: 200px; height: 90px; position:relative; left:3px; top: 0px;" align="right" />
    </button>

<script>
function add_frame(){

document.getElementById('xnat').style.border = "3px solid blue";

}

function add_border(){

document.getElementById('redcap').style.border = "3px solid red";

}
</script>

 

What I obtain are two buttons, which bring me to incorrect links of Keycloak. 

 

Any help would be so appreciated.

Thank you so much in advance.

 

Matteo

 

Il giorno giovedì 6 ottobre 2022 alle 11:23:36 UTC+2 Matteo Riva ha scritto:

UPDATE 2: After following the first steps of the site I cited in the previous message, I get this error:

 

Internal Server Error

 

And the page is completely blank. 

In summary, after I create the new folder "login" in "custom" and if I subsequently select "custom" from Themes....

 

....and I reload the page, it seems Keycloak does not read the login page in a correct way anymore. I will try it again in order to see if I can fix it in some way.

Anyone could tell me if you succeeded in changing your login page, please? If yes, how you did it? Do you know how to add the two windows I said in my first message?

 

Please, any help would be so appreciated! Thank you so much.

Matteo

 

--
You received this message because you are subscribed to the Google Groups "Keycloak User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keycloak-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-user/93c99357-fd71-4f72-8158-2a3ff2eabc85n%40googlegroups.com.

Matteo Riva

unread,
Oct 13, 2022, 3:20:04 AM10/13/22
to Keycloak User
Hello David,

Thank you so so much for your reply!
Yes, you are right: yesterday I tried to delete che login.css file, but my web page could see a css file anyway. 
Why? I searched for some solution and I found that I had to do Ctrl+Shift+I --> Network --> Activate "Disable Cache" --> Deactivate "Disable Cache". Then everything went alright! :)
In summary, the login page was loading the css file present in /opt/keycloak/standalone/tmp/kc-gzip-cache/pe6yq and not in /opt/keycloak/themes/keycloak/login/resources/css.

Could you tell me if it is a good solution to the riddle?

Thank you so much again! Really appreciated!

Matteo 

Reply all
Reply to author
Forward
0 new messages