@@ -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