Skip to content

Commit c2563ab

Browse files
committed
Discovery Service support
1 parent 8e37571 commit c2563ab

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,17 @@ example::
658658
coverage report -m
659659

660660

661+
Contributing
662+
============
663+
664+
Please open Issues to start debate regarding the requested
665+
features, or the patch that you would apply. We do not use
666+
a strict submission format, please try to be more concise as possibile.
667+
668+
The Pull Request MUST be done on the dev branch, please don't
669+
push code directly on the master branch.
670+
671+
661672
FAQ
662673
===
663674

djangosaml2/views.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,33 @@ def get(self, request, *args, **kwargs):
148148
logger.exception(msg.format(excp))
149149
return HttpResponse(msg.format('Please contact technical support.'), status=500)
150150

151-
# is a embedded wayf needed?
151+
# is a embedded wayf or DiscoveryService needed?
152152
configured_idps = available_idps(conf)
153153
selected_idp = request.GET.get('idp', None)
154-
if selected_idp is None and len(configured_idps) > 1:
155-
logger.debug('A discovery process is needed')
156-
return render(request, self.wayf_template, {
157-
'available_idps': configured_idps.items(),
158-
'came_from': next_path,
159-
})
154+
155+
# Do we have a Discovery Service?
156+
if not selected_idp:
157+
discovery_service = getattr(settings, 'SAML2_DISCO_URL', None)
158+
if discovery_service:
159+
# We have to build the URL to redirect to with all the information
160+
# for the Discovery Service to know how to send the flow back to us
161+
logger.debug(("A discovery process is needed trough a"
162+
"Discovery Service: {}").format(discovery_service))
163+
login_url = request.build_absolute_uri(reverse('saml2_login'))
164+
login_url = '{0}?next={1}'.format(login_url,
165+
urlquote(came_from, safe=''))
166+
ds_url = '{0}?entityID={1}&return={2}&returnIDParam=idp'
167+
ds_url = ds_url.format(discovery_service,
168+
urlquote(getattr(conf,'entityid'), safe=''),
169+
urlquote(login_url, safe=''))
170+
return HttpResponseRedirect(ds_url)
171+
172+
elif len(configured_idps) > 1:
173+
logger.debug('A discovery process trough WAYF page is needed')
174+
return render(request, self.wayf_template, {
175+
'available_idps': configured_idps.items(),
176+
'came_from': next_path,
177+
})
160178

161179
# is the first one, otherwise next logger message will print None
162180
if not configured_idps:

0 commit comments

Comments
 (0)