Merge pull request #1843 from timnyborg/master

Allow choosing a SAML entityid
This commit is contained in:
mdipierro
2018-02-09 12:26:34 -06:00
committed by GitHub
+10 -6
View File
@@ -104,11 +104,12 @@ def obj2dict(obj, processed=None):
types.BuiltinFunctionType, types.BuiltinFunctionType,
types.BuiltinMethodType)) types.BuiltinMethodType))
def saml2_handler(session, request, config_filename = None): def saml2_handler(session, request, config_filename = None, entityid = None):
config_filename = config_filename or os.path.join(request.folder,'private','sp_conf') config_filename = config_filename or os.path.join(request.folder,'private','sp_conf')
client = Saml2Client(config_file = config_filename) client = Saml2Client(config_file = config_filename)
idps = client.metadata.with_descriptor("idpsso") if not entityid:
entityid = idps.keys()[0] idps = client.metadata.with_descriptor("idpsso")
entityid = idps.keys()[0]
bindings = [BINDING_HTTP_REDIRECT, BINDING_HTTP_POST] bindings = [BINDING_HTTP_REDIRECT, BINDING_HTTP_POST]
binding, destination = client.pick_binding( binding, destination = client.pick_binding(
"single_sign_on_service", bindings, "idpsso", entity_id=entityid) "single_sign_on_service", bindings, "idpsso", entity_id=entityid)
@@ -119,7 +120,7 @@ def saml2_handler(session, request, config_filename = None):
if not request.vars.SAMLResponse: if not request.vars.SAMLResponse:
req_id, req = client.create_authn_request(destination, binding=binding) req_id, req = client.create_authn_request(destination, binding=binding)
relay_state = web2py_uuid().replace('-','') relay_state = web2py_uuid().replace('-','')
session.saml_outstanding_queries = {req_id: request.url} session.saml_outstanding_queries = {req_id: request.url}
session.saml_req_id = req_id session.saml_req_id = req_id
http_args = client.apply_binding(binding, str(req), destination, http_args = client.apply_binding(binding, str(req), destination,
relay_state=relay_state) relay_state=relay_state)
@@ -145,7 +146,7 @@ class Saml2Auth(object):
username=lambda v:v['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn'][0], username=lambda v:v['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn'][0],
email=lambda v:v['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn'][0], email=lambda v:v['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn'][0],
user_id=lambda v:v['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn'][0], user_id=lambda v:v['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn'][0],
), logout_url=None, change_password_url=None): ), logout_url=None, change_password_url=None, entityid=None):
self.config_file = config_file self.config_file = config_file
self.maps = maps self.maps = maps
@@ -154,9 +155,12 @@ class Saml2Auth(object):
# URL to let users change their password in the IDP system # URL to let users change their password in the IDP system
self.saml_change_password_url = change_password_url self.saml_change_password_url = change_password_url
# URL to specify an IDP if using federation metadata or an MDQ
self.entityid = entityid
def login_url(self, next="/"): def login_url(self, next="/"):
d = saml2_handler(current.session, current.request) d = saml2_handler(current.session, current.request, entityid=self.entityid)
if 'url' in d: if 'url' in d:
redirect(d['url']) redirect(d['url'])
elif 'error' in d: elif 'error' in d: