Skip to content

Commit b1be513

Browse files
authored
Default SSO roles support (#539)
1 parent 8a2e05f commit b1be513

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

descope/management/sso_settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__(
122122
idp_cert: str,
123123
attribute_mapping: Optional[AttributeMapping] = None,
124124
role_mappings: Optional[List[RoleMapping]] = None,
125+
default_sso_roles: Optional[List[str]] = None,
125126
# NOTICE - the following fields should be overridden only in case of SSO migration, otherwise, do not modify these fields
126127
sp_acs_url: Optional[str] = None,
127128
sp_entity_id: Optional[str] = None,
@@ -131,6 +132,7 @@ def __init__(
131132
self.idp_cert = idp_cert
132133
self.attribute_mapping = attribute_mapping
133134
self.role_mappings = role_mappings
135+
self.default_sso_roles = default_sso_roles
134136
self.sp_acs_url = sp_acs_url
135137
self.sp_entity_id = sp_entity_id
136138

@@ -145,13 +147,15 @@ def __init__(
145147
idp_metadata_url: str,
146148
attribute_mapping: Optional[AttributeMapping] = None,
147149
role_mappings: Optional[List[RoleMapping]] = None,
150+
default_sso_roles: Optional[List[str]] = None,
148151
# NOTICE - the following fields should be overridden only in case of SSO migration, otherwise, do not modify these fields
149152
sp_acs_url: Optional[str] = None,
150153
sp_entity_id: Optional[str] = None,
151154
):
152155
self.idp_metadata_url = idp_metadata_url
153156
self.attribute_mapping = attribute_mapping
154157
self.role_mappings = role_mappings
158+
self.default_sso_roles = default_sso_roles
155159
self.sp_acs_url = sp_acs_url
156160
self.sp_entity_id = sp_entity_id
157161

@@ -548,6 +552,7 @@ def _compose_configure_saml_settings_body(
548552
"roleMappings": SSOSettings._role_mapping_to_dict(
549553
settings.role_mappings
550554
),
555+
"defaultSSORoles": settings.default_sso_roles,
551556
},
552557
"redirectUrl": redirect_url,
553558
"domains": domains,
@@ -576,6 +581,7 @@ def _compose_configure_saml_settings_by_metadata_body(
576581
"roleMappings": SSOSettings._role_mapping_to_dict(
577582
settings.role_mappings
578583
),
584+
"defaultSSORoles": settings.default_sso_roles,
579585
},
580586
"redirectUrl": redirect_url,
581587
"domains": domains,

tests/management/test_sso_settings.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_load_settings(self):
9090
network_resp = mock.Mock()
9191
network_resp.ok = True
9292
network_resp.json.return_value = json.loads(
93-
"""{"tenant": {"id": "T2AAAA", "name": "myTenantName", "selfProvisioningDomains": [], "customAttributes": {}, "authType": "saml", "domains": ["lulu", "kuku"]}, "saml": {"idpEntityId": "", "idpSSOUrl": "", "idpCertificate": "", "idpMetadataUrl": "https://dummy.com/metadata", "spEntityId": "", "spACSUrl": "", "spCertificate": "", "attributeMapping": {"name": "name", "email": "email", "username": "", "phoneNumber": "phone", "group": "", "givenName": "", "middleName": "", "familyName": "", "picture": "", "customAttributes": {}}, "groupsMapping": [], "redirectUrl": ""}, "oidc": {"name": "", "clientId": "", "clientSecret": "", "redirectUrl": "", "authUrl": "", "tokenUrl": "", "userDataUrl": "", "scope": [], "JWKsUrl": "", "userAttrMapping": {"loginId": "sub", "username": "", "name": "name", "email": "email", "phoneNumber": "phone_number", "verifiedEmail": "email_verified", "verifiedPhone": "phone_number_verified", "picture": "picture", "givenName": "given_name", "middleName": "middle_name", "familyName": "family_name"}, "manageProviderTokens": false, "callbackDomain": "", "prompt": [], "grantType": "authorization_code", "issuer": ""}}"""
93+
"""{"tenant": {"id": "T2AAAA", "name": "myTenantName", "selfProvisioningDomains": [], "customAttributes": {}, "authType": "saml", "domains": ["lulu", "kuku"]}, "saml": {"idpEntityId": "", "idpSSOUrl": "", "idpCertificate": "", "defaultSSORoles": ["aa", "bb"], "idpMetadataUrl": "https://dummy.com/metadata", "spEntityId": "", "spACSUrl": "", "spCertificate": "", "attributeMapping": {"name": "name", "email": "email", "username": "", "phoneNumber": "phone", "group": "", "givenName": "", "middleName": "", "familyName": "", "picture": "", "customAttributes": {}}, "groupsMapping": [], "redirectUrl": ""}, "oidc": {"name": "", "clientId": "", "clientSecret": "", "redirectUrl": "", "authUrl": "", "tokenUrl": "", "userDataUrl": "", "scope": [], "JWKsUrl": "", "userAttrMapping": {"loginId": "sub", "username": "", "name": "name", "email": "email", "phoneNumber": "phone_number", "verifiedEmail": "email_verified", "verifiedPhone": "phone_number_verified", "picture": "picture", "givenName": "given_name", "middleName": "middle_name", "familyName": "family_name"}, "manageProviderTokens": false, "callbackDomain": "", "prompt": [], "grantType": "authorization_code", "issuer": ""}}"""
9494
)
9595
mock_get.return_value = network_resp
9696
resp = client.mgmt.sso.load_settings("T2AAAA")
@@ -101,6 +101,10 @@ def test_load_settings(self):
101101
self.assertEqual(
102102
saml_settings.get("idpMetadataUrl", ""), "https://dummy.com/metadata"
103103
)
104+
self.assertEqual(
105+
saml_settings.get("defaultSSORoles", ""),
106+
["aa", "bb"],
107+
)
104108
mock_get.assert_called_with(
105109
f"{common.DEFAULT_BASE_URL}{MgmtV1.sso_load_settings_path}",
106110
headers={
@@ -233,6 +237,7 @@ def test_configure_saml_settings(self):
233237
idp_cert="cert",
234238
sp_acs_url="http://spacsurl.com",
235239
sp_entity_id="spentityid",
240+
default_sso_roles=["aa", "bb"],
236241
),
237242
"https://redirect.com",
238243
["domain.com"],
@@ -261,6 +266,7 @@ def test_configure_saml_settings(self):
261266
role_mappings=[RoleMapping(groups=["grp1"], role_name="rl1")],
262267
sp_acs_url="http://spacsurl.com",
263268
sp_entity_id="spentityid",
269+
default_sso_roles=["aa", "bb"],
264270
),
265271
"https://redirect.com",
266272
["domain.com"],
@@ -293,6 +299,7 @@ def test_configure_saml_settings(self):
293299
"roleMappings": [{"groups": ["grp1"], "roleName": "rl1"}],
294300
"spACSUrl": "http://spacsurl.com",
295301
"spEntityId": "spentityid",
302+
"defaultSSORoles": ["aa", "bb"],
296303
},
297304
"redirectUrl": "https://redirect.com",
298305
"domains": ["domain.com"],
@@ -343,6 +350,7 @@ def test_configure_saml_settings_by_metadata(self):
343350
role_mappings=[RoleMapping(groups=["grp1"], role_name="rl1")],
344351
sp_acs_url="http://spacsurl.com",
345352
sp_entity_id="spentityid",
353+
default_sso_roles=["aa", "bb"],
346354
),
347355
"https://redirect.com",
348356
["domain.com"],
@@ -373,6 +381,7 @@ def test_configure_saml_settings_by_metadata(self):
373381
"roleMappings": [{"groups": ["grp1"], "roleName": "rl1"}],
374382
"spACSUrl": "http://spacsurl.com",
375383
"spEntityId": "spentityid",
384+
"defaultSSORoles": ["aa", "bb"],
376385
},
377386
"redirectUrl": "https://redirect.com",
378387
"domains": ["domain.com"],

0 commit comments

Comments
 (0)