Skip to content
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
10 changes: 10 additions & 0 deletions social_core/backends/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CASOpenIdConnectAuth(OpenIdConnectAuth):
SOCIAL_AUTH_CAS_OIDC_ENDPOINT = 'https://.....' # endpoint without /.well-known/openid-configuration
SOCIAL_AUTH_CAS_KEY = '<client_id>'
SOCIAL_AUTH_CAS_SECRET = '<client_secret>'
SOCIAL_AUTH_CAS_ALLOW_GROUPS = []
"""

name = "cas"
Expand Down Expand Up @@ -59,3 +60,12 @@ def get_user_details(self, response):
"first_name": attributes.get("given_name"),
"last_name": attributes.get("family_name"),
}

def auth_allowed(self, response, details):
allow_groups = set(self.setting("ALLOW_GROUPS", set()))
groups = set(response.get("groups", set()))
return (
super().auth_allowed(response, details)
if groups.intersection(allow_groups) or not allow_groups
else False
)
6 changes: 6 additions & 0 deletions social_core/tests/backends/test_cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def extra_settings(self):
settings.update(
{
f"SOCIAL_AUTH_{self.name}_OIDC_ENDPOINT": f"{ROOT_URL}oidc",
f"SOCIAL_AUTH_{self.name}_ALLOW_GROUPS": [
"users",
],
f"SOCIAL_AUTH_{self.name}_WHITELISTED_DOMAINS": [
"example.net",
],
}
)
return settings
Expand Down
Loading