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

Makes it easy to update the login url #80

Open
wants to merge 5 commits into
base: main
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
9 changes: 7 additions & 2 deletions shibboleth/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

#At a minimum you will need username,
#At a minimum you will need username,
default_shib_attributes = {
"REMOTE_USER": (True, "username"),
}
}

SHIB_ATTRIBUTE_MAP = getattr(settings, 'SHIBBOLETH_ATTRIBUTE_MAP', default_shib_attributes)
#Set to true if you are testing and want to insert sample headers.
Expand All @@ -30,3 +30,8 @@
#LOGOUT_REDIRECT_URL specifies a default logout page that will always be used when
#users logout from Shibboleth.
LOGOUT_REDIRECT_URL = getattr(settings, 'SHIBBOLETH_LOGOUT_REDIRECT_URL', None)
#This is the parameter used to redirect after login. Old versions was used 'next' parameter.
LOGIN_URL_PARAMETER = getattr(settings, 'SHIBBOLETH_LOGIN_URL_PARAMETER', 'target')
#This should look like: /login
#This is the LOGIN_URL_PARAMETER value. The endpoint after login
LOGIN_REDIRECT_URL = getattr(settings, 'SHIBBOLETH_LOGIN_REDIRECT_URL', None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests for these LOGIN settings would be nice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will do.

17 changes: 9 additions & 8 deletions shibboleth/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
from django.urls import reverse
from urllib.parse import quote

try:
from app_settings import LOGOUT_URL, LOGOUT_REDIRECT_URL, LOGIN_REDIRECT_URL, LOGIN_URL_PARAMETER
except ImportError:
from .app_settings import LOGOUT_URL, LOGOUT_REDIRECT_URL, LOGIN_REDIRECT_URL, LOGIN_URL_PARAMETER

def login_link(request):
"""
This assumes your login link is the Shibboleth login page for your server
By default: this assumes your login link is the Shibboleth login page for your server
and uses the 'target' url parameter.
"""
full_path = quote(request.get_full_path())
full_path = LOGIN_REDIRECT_URL or quote(request.get_full_path())
login = reverse('shibboleth:login')
ll = "%s?target=%s" % (login, full_path)
ll = "%s?%s=%s" % (login, LOGIN_URL_PARAMETER, full_path)
return { 'login_link': ll }

def logout_link(request, *args):
"""
This assumes your login link is the Shibboleth login page for your server
This assumes your login link is the Shibboleth login page for your server
and uses the 'target' url parameter.
e.g: https://school.edu/Shibboleth.sso/Login
"""
try:
from app_settings import LOGOUT_URL, LOGOUT_REDIRECT_URL
except ImportError:
from .app_settings import LOGOUT_URL, LOGOUT_REDIRECT_URL
#LOGOUT_REDIRECT_URL specifies a default logout page that will always be used when
#users logout from Shibboleth.
target = LOGOUT_REDIRECT_URL or quote(request.build_absolute_uri())
Expand Down