Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button style config options #9

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ To install ckanext-keycloak:

Configuration settings to run the extension

```

ckanext.keycloak.server_url = link_to_keycloack_authentication_url
ckanext.keycloak.client_id = client_id
ckanext.keycloak.realm_name = realm_name
ckanext.keycloak.redirect_uri = redirect_url
ckanext.keycloak.client_secret_key = client_secret_key
```
ckanext.keycloak.button_style = google/azure (if empty it will have the default stile)
ckanext.keycloak.enable_ckan_internal_login = True or False


## Developer installation

Expand Down
56 changes: 55 additions & 1 deletion ckanext/keycloak/assets/css/keycloak.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,58 @@
position: inherit;
margin-top: 1rem;
}
}
}

.azurebtn {
padding: 8px 16px 5px 42px;
margin-right: 10px;
border: 1px;
border-style: solid;

border-radius: 3px;
box-shadow: 0 -1px 0 rgba(0, 0, 0, .04), 0 1px 1px rgba(0, 0, 0, .25);

color: #000000;
font-size: 14px;
font-weight: 500;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",sans-serif;

background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAABHVBMVEVHcEw0t+0kisINUpgMT5QVcbwnl+AegsYHZbYGabwtpOc4w/Epl+ILVp4wq+YTXpo7yvMvqOgqmeMKXKgJYK4HZLUoluEOUJQ2u+4vqOgupec1uO0NUpY3vu8touYOUJQ0tewzsus4wfA5xPEsn+UNPnwLWqQOS406x/INUpYxruowrOYgd6k7yvMOWZ4LWqQKXKczse0KXKcup+Yyr+oJX60Yi9QDa8AIY7IHZrcHZrcHZrcAeNMAgN8OfM0AedUAdc84wvEysOstpOcJX6wrnuUCdMoHY7MztesPTo0MVJs6x/MAd9I3v+0MT5Q2u+41uO0MVp8wq+kLWKELWqQqnOIJYa8QfssWZqIcdq4kib4zsN8sns8citMEbsTGL1GGAAAAQXRSTlMAGwq7aBT+BPtOMD5MlPP7+f7u1H0r9x7zWIJiPN6s3o21vpfQQTSYbPTXzO7uzO9ZaP39mq2LievJ4PHeDe5tvTWfrhoAAADFSURBVBjTVcxFEsJAAADBACGCu7u7u8cVd/3/MygoWJY59mEQ5F26ZLOVjQgcap0rSu6PstJVoZKwaHXSjaISWoi8UelCzcMaiEL5xXm59MF/VF6cxNUqCJFZlq0WUYz9BNet15UiTcdxQHrndmtu0XTh989Udzu0vtlYDIBqDZbodpp2ux+QixVUld8zTADc2yz7UHmMYSI4uB8O/RF/57iU/kPuniC4pvyR4xzfP0kIBDmeHbE9ZvrSkBi4EXLi8The9ARvhx6sSwjytgAAAABJRU5ErkJggg==');
background-repeat: no-repeat;
background-position: 9px 9px;
background-color: #ffffff;

&:focus {
outline: none;
box-shadow:
0 -1px 0 rgba(0, 0, 0, .04),
0 2px 4px rgba(0, 0, 0, .25),
0 0 0 3px #c8dafc;
}

}
.azurebtn:hover {
background-color: #e6e6e6;
}

.register-azure{
position: relative;
}

.azure-button{
position: absolute;
right: 17%;
bottom: 0%;
}

@media only screen and (max-width: 900px) {

.register-azure{
position: inherit;
}

.azure-button{
position: inherit;
margin-top: 1rem;
}
}
18 changes: 18 additions & 0 deletions ckanext/keycloak/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ckan.model as model
import ckan.plugins.toolkit as tk
from os import environ


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -34,9 +35,11 @@ def ensure_unique_username_from_email(email):

return cleaned_localpart


def process_user(userinfo):
return _get_user_by_email(userinfo.get('email')) or _create_user(userinfo)


def _get_user_by_email(email):
user = model.User.by_email(email)
if user and isinstance(user, list):
Expand All @@ -46,6 +49,7 @@ def _get_user_by_email(email):

return user


def activate_user_if_deleted(user):
u'''Reactivates deleted user.'''
if not user:
Expand All @@ -55,6 +59,7 @@ def activate_user_if_deleted(user):
user.commit()
log.info(u'User {} reactivated'.format(user.name))


def _create_user(userinfo):
context = {
u'ignore_auth': True,
Expand All @@ -64,3 +69,16 @@ def _create_user(userinfo):
)(context, userinfo)

return _get_user_by_email(created_user_dict['email'])


def button_style():

return tk.config.get('ckanext.keycloak.button_style',
environ.get('CKANEXT__KEYCLOAK__BUTTON_STYLE'))


def enable_internal_login():

return tk.asbool(tk.config.get(
'ckanext.keycloak.enable_ckan_internal_login',
environ.get('CKANEXT__KEYCLOAK__CKAN_INTERNAL_LOGIN')))
14 changes: 12 additions & 2 deletions ckanext/keycloak/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import ckan.plugins.toolkit as toolkit

from ckanext.keycloak.views import get_blueprint
from ckanext.keycloak import helpers as h


class KeycloakPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)
plugins.implements(plugins.IBlueprint)
plugins.implements(plugins.ITemplateHelpers)

# IConfigurer

Expand All @@ -14,6 +17,13 @@ def update_config(self, config_):
toolkit.add_public_directory(config_, 'public')
toolkit.add_resource('assets', 'keycloak')


def get_blueprint(self):
return get_blueprint()
return get_blueprint()

# ITemplateHelpers

def get_helpers(self):
return {
'button_style': h.button_style,
'enable_internal_login': h.enable_internal_login,
}
17 changes: 15 additions & 2 deletions ckanext/keycloak/templates/user/snippets/login_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@

{% ckan_extends %}
{% block login_button %}
<a class="gbtn btn btn-default" href="{{ h.url_for('keycloak.sso') }}">{{ _('Sign in with Google') }}</a>
<button class="btn btn-primary" type="submit">{{ _('Login') }}</button>

{% set button_style = h.button_style() %}
{% if button_style == "google" %}
<a class="gbtn btn btn-default" href="{{ h.url_for('keycloak.sso') }}">{{ _('Sign in with Google') }}</a>
{% elif button_style == "azure" %}
<a class="azurebtn btn btn-defaul" href="{{ h.url_for('keycloak.sso') }}">{{ _('Sign in with AzureAD') }}</a>
{% else %}
<a class="btn btn-primary" href="{{ h.url_for('keycloak.sso') }}">{{ _('SSO') }}</a>
{% endif %}

{% set enable_ckan_login = h.enable_internal_login() %}
{% if enable_ckan_login %}
<button class="btn btn-primary" type="submit">{{ _('Login') }}</button>
{% else%}
{% endif %}

{% endblock %}
Loading