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

Enable ckan auth #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions ckanext/oauth2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def __init__(self, name=None):
def before_map(self, m):
log.debug('Setting up the redirections to the OAuth2 service')

m.connect('/user/login',
if self.enable_ckan_auth:
base = '/oauth2'
else:
base = ''

m.connect(base+'/user/login',
controller='ckanext.oauth2.controller:OAuth2Controller',
action='login')

Expand All @@ -111,15 +116,15 @@ def before_map(self, m):

# Redirect the user to the OAuth service register page
if self.register_url:
m.redirect('/user/register', self.register_url)
m.redirect(base+'/user/register', self.register_url)

# Redirect the user to the OAuth service reset page
if self.reset_url:
m.redirect('/user/reset', self.reset_url)
m.redirect(base+'/user/reset', self.reset_url)

# Redirect the user to the OAuth service reset page
if self.edit_url:
m.redirect('/user/edit/{user}', self.edit_url)
m.redirect(base+'/user/edit/{user}', self.edit_url)

return m

Expand Down Expand Up @@ -179,6 +184,7 @@ def update_config(self, config):
self.reset_url = os.environ.get("CKAN_OAUTH2_RESET_URL", config.get('ckan.oauth2.reset_url', None))
self.edit_url = os.environ.get("CKAN_OAUTH2_EDIT_URL", config.get('ckan.oauth2.edit_url', None))
self.authorization_header = os.environ.get("CKAN_OAUTH2_AUTHORIZATION_HEADER", config.get('ckan.oauth2.authorization_header', 'Authorization')).lower()
self.enable_ckan_auth = os.environ.get("CKAN_OAUTH2_ENABLE_CKAN_AUTH", config.get('ckan.oauth2.enable_ckan_auth', False))

# Add this plugin's templates dir to CKAN's extra_template_paths, so
# that CKAN will use this plugin's custom templates.
Expand Down
10 changes: 4 additions & 6 deletions ckanext/oauth2/templates/header.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% ckan_extends %}

{% if header_account_notlogged is defined %}
{% block header_account_notlogged %}
<li>{% link_for _('Log in'), controller='user', action='login' %}</li>
<li>{% link_for _('Register'), controller='user', action='register', class_='sub' %}</li>
{% endblock %}
{% endif %}
{% block header_account_notlogged %}
<li>{% link_for _('OAuth Log in'), named_route='oauth2.login' %}</li>
{{ super() }}
{% endblock %}