diff --git a/README.md b/README.md index be722b6..c2b95cb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ckanext/keycloak/assets/css/keycloak.css b/ckanext/keycloak/assets/css/keycloak.css index e5f4934..97f6571 100644 --- a/ckanext/keycloak/assets/css/keycloak.css +++ b/ckanext/keycloak/assets/css/keycloak.css @@ -50,4 +50,58 @@ position: inherit; margin-top: 1rem; } - } \ No newline at end of file + } + +.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; + } + } \ No newline at end of file diff --git a/ckanext/keycloak/helpers.py b/ckanext/keycloak/helpers.py index d44e2da..e1a849d 100644 --- a/ckanext/keycloak/helpers.py +++ b/ckanext/keycloak/helpers.py @@ -7,6 +7,7 @@ import ckan.model as model import ckan.plugins.toolkit as tk +from os import environ log = logging.getLogger(__name__) @@ -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): @@ -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: @@ -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, @@ -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'))) diff --git a/ckanext/keycloak/plugin.py b/ckanext/keycloak/plugin.py index 583eb33..2874f70 100644 --- a/ckanext/keycloak/plugin.py +++ b/ckanext/keycloak/plugin.py @@ -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 @@ -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() \ No newline at end of file + return get_blueprint() + + # ITemplateHelpers + + def get_helpers(self): + return { + 'button_style': h.button_style, + 'enable_internal_login': h.enable_internal_login, + } diff --git a/ckanext/keycloak/templates/user/snippets/login_form.html b/ckanext/keycloak/templates/user/snippets/login_form.html index 17bde71..c27f041 100644 --- a/ckanext/keycloak/templates/user/snippets/login_form.html +++ b/ckanext/keycloak/templates/user/snippets/login_form.html @@ -17,7 +17,20 @@ {% ckan_extends %} {% block login_button %} - {{ _('Sign in with Google') }} - + +{% set button_style = h.button_style() %} +{% if button_style == "google" %} + {{ _('Sign in with Google') }} +{% elif button_style == "azure" %} + {{ _('Sign in with AzureAD') }} +{% else %} + {{ _('SSO') }} +{% endif %} + +{% set enable_ckan_login = h.enable_internal_login() %} +{% if enable_ckan_login %} + +{% else%} +{% endif %} {% endblock %} \ No newline at end of file